Skip to content

Commit

Permalink
Fix QDCSS not parsing singlequoted or unquoted values
Browse files Browse the repository at this point in the history
  • Loading branch information
unascribed committed May 15, 2022
1 parent 52216bb commit 91b36ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ targetCompatibility = 8

group = "com.unascribed"
archivesBaseName = "NilLoader"
version = "1.1.1"
version = "1.1.2-pre1"

tasks.withType(JavaCompile) {
options.release = 8
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/nilloader/api/lib/qdcss/QDCSS.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public int size() {

private static final Pattern JUNK_PATTERN = Pattern.compile("^(\\s*(/\\*.*?\\*/)?\\s*)*$", Pattern.DOTALL);
private static final Pattern RULESET_PATTERN = Pattern.compile("[#.]?(@?\\w+?)\\s*\\{(.*?)\\}", Pattern.DOTALL);
private static final Pattern RULE_PATTERN = Pattern.compile("(\\S+?)\\s*:\\s*(?:\\\"(.*?)(?<!\\\\)\\\"|'(.*?)(?<!\\\\)'|(\\S)+?)\\s*(;|$)");
private static final Pattern RULE_PATTERN = Pattern.compile("(\\S+?)\\s*:\\s*(?:\\\"(.*?)(?<!\\\\)\\\"|'(.*?)(?<!\\\\)'|(\\S+?))\\s*(?:;|$)");

public static QDCSS load(String fileName, String s) throws SyntaxErrorException {
// vanilla CSS is a very simple grammar, so we can parse it using only regexes
Expand All @@ -376,7 +376,14 @@ public static QDCSS load(String fileName, String s) throws SyntaxErrorException
throw new SyntaxErrorException("Expected a rule near line "+getLine(s, ruleset.start(2)+rule.start())+" in "+fileName);
}
String property = rule.group(1);
String value = rule.group(2);
String value;
if (rule.group(2) != null) {
value = rule.group(2);
} else if (rule.group(3) != null) {
value = rule.group(3);
} else {
value = rule.group(4);
}
String key = selector+"."+property;
if (!data.containsKey(key)) {
data.put(key, new ArrayList<>());
Expand Down

0 comments on commit 91b36ae

Please sign in to comment.