Skip to content

Commit 80fc8f8

Browse files
author
David Haeffner
committed
Added backslash escaping to stringEscape and added test coverage for sendKeys command emitting in selianize to verify it. Updated snapshots accordingly.
1 parent ce759e3 commit 80fc8f8

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

packages/code-export-java-junit/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class LoginTest {
4141
driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\");
4242
driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\");
4343
driver.findElement(By.cssSelector(\\"#login button\\")).click();
44-
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\n×\\"));
44+
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\\\\\\\\\\\\\n×\\"));
4545
}
4646
@Test
4747
public void invalidcredentials() {
@@ -50,7 +50,7 @@ public class LoginTest {
5050
driver.findElement(By.id(\\"username\\")).sendKeys(\\"blah\\");
5151
driver.findElement(By.id(\\"password\\")).sendKeys(\\"blah\\");
5252
driver.findElement(By.cssSelector(\\"#login button\\")).click();
53-
assertThat(driver.findElement(By.id(\\"flash\\")).getText(), is(\\"Your username is invalid!\\\\n×\\"));
53+
assertThat(driver.findElement(By.id(\\"flash\\")).getText(), is(\\"Your username is invalid!\\\\\\\\\\\\\\\\n×\\"));
5454
}
5555
}
5656
"
@@ -388,7 +388,7 @@ public class LoginTest {
388388
driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\");
389389
driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\");
390390
driver.findElement(By.cssSelector(\\"#login button\\")).click();
391-
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\n×\\"));
391+
assertThat(driver.findElement(By.cssSelector(\\".flash.success\\")).getText(), is(\\"You logged into a secure area!\\\\\\\\\\\\\\\\n×\\"));
392392
}
393393
}
394394
"

packages/code-export-javascript-mocha/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ describe('login', function() {
2222
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\")
2323
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\")
2424
await driver.findElement(By.css(\\"#login button\\")).click()
25-
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\")
25+
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\\\\\\\\\\\\\")
2626
})
2727
it('invalid credentials', async function() {
2828
await driver.get(\\"http://the-internet.herokuapp.com/login\\")
2929
await driver.setRect(1440, 1177)
3030
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"blah\\")
3131
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"blah\\")
3232
await driver.findElement(By.css(\\"#login button\\")).click()
33-
assert(await driver.findElement(By.id(\\"flash\\")).getText() == \\"Your username is invalid!\\\\\\")
33+
assert(await driver.findElement(By.id(\\"flash\\")).getText() == \\"Your username is invalid!\\\\\\\\\\\\\\\\\\")
3434
})
3535
})
3636
"
@@ -258,7 +258,7 @@ describe('login', function() {
258258
await driver.findElement(By.id(\\"username\\")).sendKeys(\\"tomsmith\\")
259259
await driver.findElement(By.id(\\"password\\")).sendKeys(\\"SuperSecretPassword!\\")
260260
await driver.findElement(By.css(\\"#login button\\")).click()
261-
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\")
261+
assert(await driver.findElement(By.css(\\".flash.success\\")).getText() == \\"You logged into a secure area!\\\\\\\\\\\\\\\\\\")
262262
})
263263
})
264264
"

packages/code-export-python-pytest/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ class TestLogin():
2626
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"tomsmith\\")
2727
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"SuperSecretPassword!\\")
2828
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
29-
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\"
29+
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\\\\\\\\\\\\\"
3030
3131
def test_invalidcredentials(self):
3232
self.driver.get(\\"http://the-internet.herokuapp.com/login\\")
3333
self.driver.set_window_size(1440, 1177)
3434
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"blah\\")
3535
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"blah\\")
3636
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
37-
assert self.driver.find_element(By.ID, \\"flash\\").text == \\"Your username is invalid!\\\\\\"
37+
assert self.driver.find_element(By.ID, \\"flash\\").text == \\"Your username is invalid!\\\\\\\\\\\\\\\\\\"
3838
3939
"
4040
`;
@@ -268,7 +268,7 @@ class TestLogin():
268268
self.driver.find_element(By.ID, \\"username\\").send_keys(\\"tomsmith\\")
269269
self.driver.find_element(By.ID, \\"password\\").send_keys(\\"SuperSecretPassword!\\")
270270
self.driver.find_element(By.CSS_SELECTOR, \\"#login button\\").click()
271-
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\"
271+
assert self.driver.find_element(By.CSS_SELECTOR, \\".flash.success\\").text == \\"You logged into a secure area!\\\\\\\\\\\\\\\\\\"
272272
273273
"
274274
`;

packages/selianize/__tests__/__snapshots__/command.spec.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ exports[`command code emitter should emit \`set window size\` command 1`] = `
3434
console.log('Unable to resize window. Skipping.');
3535
};"
3636
`;
37+
38+
exports[`keys preprocessor should not unescape escaped characters 1`] = `"await driver.wait(until.elementLocated(By.id(\`t\`)), configuration.timeout);await driver.findElement(By.id(\`t\`)).then(element => {return element.sendKeys(\`AAAAAA\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`BBBBBB\`);});"`;

packages/selianize/__tests__/command.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ import {
2020
Commands,
2121
ControlFlowCommandNames,
2222
} from '../../selenium-ide/src/neo/models/Command'
23+
import { stringEscape } from '@seleniumhq/side-utils'
2324

2425
describe('keys preprocessor', () => {
26+
it('should not unescape escaped characters', () => {
27+
const command = {
28+
command: 'sendKeys',
29+
target: 'id=t',
30+
value: stringEscape('AAAAAA\\`BBBBBB'), // eslint-disable-line
31+
}
32+
return expect(CommandEmitter.emit(command)).resolves.toMatchSnapshot()
33+
})
2534
it('should not affect hardcoded strings', () => {
2635
const command = {
2736
command: 'sendKeys',

packages/side-utils/__test__/src/string-escape/index.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ describe('String escape', () => {
77
it('should escape backticks', () => {
88
expect(stringEscape('AAAAA`BBBBB')).toEqual('AAAAA\\`BBBBB')
99
})
10+
it('should escape backslashes', () => {
11+
expect(stringEscape('AAAAA\\`BBBBB')).toEqual('AAAAA\\\\\\`BBBBB') // eslint-disable-line
12+
})
1013
it('should escape single-quotes', () => {
1114
expect(stringEscape("AAAAA'BBBBB")).toEqual("AAAAA\\'BBBBB")
1215
})

packages/side-utils/src/string-escape/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = (input, terminatingCharacter) => {
22
if (!input) return ''
3-
return input.replace(/[`'"\\\n\r\u2028\u2029]/g, character => {
3+
return input.replace(/[`'"\\\n\r\u2028\u2029\u005c]/g, character => {
44
switch (character) {
55
case `"`:
66
case `'`:
@@ -16,6 +16,8 @@ module.exports = (input, terminatingCharacter) => {
1616
return '\\u2028'
1717
case '\u2029':
1818
return '\\u2029'
19+
case '\u005c':
20+
return '\\\\'
1921
default:
2022
return character
2123
}

0 commit comments

Comments
 (0)