8000 fix(css): parse css selectors with escape sequences (#7689) by manoldonev · Pull Request #7732 · NativeScript/NativeScript · GitHub
[go: up one dir, main page]

Skip to content

fix(css): parse css selectors with escape sequences (#7689) #7732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
23 changes: 23 additions & 0 deletions tests/app/ui/styling/style-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ export function test_class_selector() {
TKUnit.assert(btnWithNoClass.style.color === undefined, "Color should not have a value");
}

export function test_class_selector_with_escape_characters() {
let page = helper.getClearCurrentPage();
let btnWithClass1: buttonModule.Button;
let btnWithClass2: buttonModule.Button;

page.css = ".test-1 { color: red; } .test-1\\/2 { color: blue }";

//// Will be styled
btnWithClass1 = new buttonModule.Button();
btnWithClass1.className = "test-1";

btnWithClass2 = new buttonModule.Button();
btnWithClass2.className = "test-1/2";

const stack = new stackModule.StackLayout();
page.content = stack;
stack.addChild(btnWithClass1);
stack.addChild(btnWithClass2);

helper.assertViewColor(btnWithClass1, "#FF0000");
helper.assertViewColor(btnWithClass2, "#0000FF");
}

export function test_multiple_class_selector() {
< 8000 /td> let page = helper.getClearCurrentPage();
let btnWithClasses: buttonModule.Button;
Expand Down
8 changes: 4 additions & 4 deletions tns-core-modules/css/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ function parseArgumentsList<T>(text: string, start: number, argument: (value: st
}
end = arg.end;
value.push(arg);

closingBracketOrCommaRegEx.lastIndex = end;
const closingBracketOrComma = closingBracketOrCommaRegEx.exec(text);
if (closingBracketOrComma) {
Expand Down Expand Up @@ -734,7 +734,7 @@ export function parseUniversalSelector(text: string, start: number = 0): Parsed<
return { start, end, value: { type: "*" }};
}

const simpleIdentifierSelectorRegEx = /(#|\.|:|\b)([_-\w][_-\w\d]*)/gy;
const simpleIdentifierSelectorRegEx = /(#|\.|:|\b)([_-\w][_-\w\d\\/]*)/gy;
export function parseSimpleIdentifierSelector(text: string, start: number = 0): Parsed<TypeSelector | ClassSelector | IdSelector | PseudoClassSelector> {
simpleIdentifierSelectorRegEx.lastIndex = start;
const result = simpleIdentifierSelectorRegEx.exec(text);
Expand All @@ -743,7 +743,7 @@ export function parseSimpleIdentifierSelector(text: string, start: number = 0):
}
const end = simpleIdentifierSelectorRegEx.lastIndex;
const type = <"#" | "." | ":" | "">result[1];
const identifier: string = result[2];
const identifier: string = result[2].replace(/\\/g, "");
const value = <TypeSelector | ClassSelector | IdSelector | PseudoClassSelector>{ type, identifier };

return { start, end, value };
Expand Down Expand Up @@ -1617,4 +1617,4 @@ export class CSSNativeScript {

return selectors;
}
}
}
0