Skip to content

Commit 4451c8a

Browse files
committed
css: support unescaped ':' in attribute name
1 parent 47ab367 commit 4451c8a

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/main/java/ch/digitalfondue/jfiveparse/CSS.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ record Combinator(int type) implements CssSelector {}
6565
record TagSelector(String name, String namespace) implements CssSelector {}
6666

6767

68-
68+
static final int IGNORE_CASE_UNKNOWN = -1;
6969
static final int IGNORE_CASE_TRUE = 0;
7070
static final int IGNORE_CASE_FALSE = 1;
7171
static final int IGNORE_CASE_QUIRKS = 2;
@@ -338,6 +338,12 @@ int parse() {
338338
name = getName(1);
339339
}
340340
}
341+
342+
// Support unescaped colons in attribute names (e.g., xml:lang)
343+
while (selector.charAt(selectorIndex) == ':') {
344+
name = name + ":" + getName(1);
345+
}
346+
341347
stripWhitespace(0);
342348
// Determine comparison operation
343349
int action = ATTR_ACTION_EXISTS;
@@ -355,7 +361,7 @@ int parse() {
355361
}
356362

357363
String value = "";
358-
int ignoreCase = -1;
364+
int ignoreCase = IGNORE_CASE_UNKNOWN;
359365

360366
if (action != ATTR_ACTION_EXISTS) {
361367
if (isQuote(charAt(selectorIndex))) {

src/test/java/ch/digitalfondue/jfiveparse/CSSTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ void checkEscapedWhitespace() {
205205
)), r);
206206
}
207207

208+
@Test
209+
void checkUnescapedColon() {
210+
var r = CSS.parseSelector("*[xml:lang|=\"es\"]");
211+
assertEquals(List.of(List.of(
212+
new CSS.UniversalSelector(null),
213+
new CSS.AttributeSelector(
214+
"xml:lang",
215+
CSS.ATTR_ACTION_HYPHEN,
216+
"es",
217+
CSS.IGNORE_CASE_UNKNOWN,
218+
null
219+
)
220+
)), r);
221+
}
222+
208223
// TODO: add all the missing String.raw tests
209224

210225
record NthExprAB(String expr, int a, int b) {}

0 commit comments

Comments
 (0)