Skip to content

Commit

Permalink
Adding a space when encoding ids starting with digits
Browse files Browse the repository at this point in the history
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 <rdbaron@gmail.com>
Signed-off-by: Jason Leyba <jmleyba@gmail.com>
  • Loading branch information
rdbaron authored and jleyba committed Apr 1, 2016
1 parent 0a6b17f commit c554cf3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/by.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function escapeCss(css) {
|| (i == 0 && c >= 0x0030 && c <= 0x0039)
|| (i == 1 && c >= 0x0030 && c <= 0x0039
&& css.charCodeAt(0) == 0x002D)) {
ret += '\\' + c.toString(16);
ret += '\\' + c.toString(16) + ' ';
continue;
}

Expand Down
12 changes: 12 additions & 0 deletions javascript/node/selenium-webdriver/test/lib/by_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ describe('by', function() {
assert.equal('css selector', locator.using);
assert.equal('*[name="foo\\"bar\\""]', locator.value);
});

it('escapes the name when it starts with a number', function() {
let locator = by.By.name('123foo"bar"')
assert.equal('css selector', locator.using);
assert.equal('*[name="\\31 23foo\\"bar\\""]', locator.value);
});

it('escapes the name when it starts with a negative number', function() {
let locator = by.By.name('-123foo"bar"')
assert.equal('css selector', locator.using);
assert.equal('*[name="-\\31 23foo\\"bar\\""]', locator.value);
});
});
});

Expand Down

0 comments on commit c554cf3

Please sign in to comment.