Skip to content

Commit 4a33bf9

Browse files
rdbaronjleyba
authored andcommitted
Adding a space when encoding ids starting with digits
escapeCss() references the following: https://drafts.csswg.org/cssom/#serialize-an-identifier > To escape a character as code point means to create a string of "\" > (U+005C), followed by the Unicode code point as the smallest possible > number of hexadecimal digits in the range 0-9 a-f (U+0030 to U+0039 and > U+0061 to U+0066) to represent the code point in base 16, *followed by a > single SPACE (U+0020).* Currently the digit is being encoded, but no SPACE is being added. Adding the SPACE. Signed-off-by: Bob Baron <[email protected]> Signed-off-by: Jason Leyba <[email protected]>
1 parent 1976737 commit 4a33bf9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

javascript/node/selenium-webdriver/lib/by.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function escapeCss(css) {
8484
|| (i == 0 && c >= 0x0030 && c <= 0x0039)
8585
|| (i == 1 && c >= 0x0030 && c <= 0x0039
8686
&& css.charCodeAt(0) == 0x002D)) {
87-
ret += '\\' + c.toString(16);
87+
ret += '\\' + c.toString(16) + ' ';
8888
continue;
8989
}
9090

javascript/node/selenium-webdriver/test/lib/by_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ describe('by', function() {
7272
assert.equal('css selector', locator.using);
7373
assert.equal('*[name="foo\\"bar\\""]', locator.value);
7474
});
75+
76+
it('escapes the name when it starts with a number', function() {
77+
let locator = by.By.name('123foo"bar"')
78+
assert.equal('css selector', locator.using);
79+
assert.equal('*[name="\\31 23foo\\"bar\\""]', locator.value);
80+
});
81+
82+
it('escapes the name when it starts with a negative number', function() {
83+
let locator = by.By.name('-123foo"bar"')
84+
assert.equal('css selector', locator.using);
85+
assert.equal('*[name="-\\31 23foo\\"bar\\""]', locator.value);
86+
});
7587
});
7688
});
7789

0 commit comments

Comments
 (0)