Skip to content

Commit

Permalink
Fix issue where android would not parse regex correctly (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute authored Mar 17, 2021
1 parent 31ae498 commit 6faaedf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/java_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
architecture: x64

- name: ✔ Test with Maven
run: mvn test -fae
run: mvn test -fae --no-transfer-progress
2 changes: 1 addition & 1 deletion .github/workflows/mal_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
echo ${{ secrets.MAL_OAUTH }} > src/test/java/resources/oauth.txt
- name: ✔ Test with Maven
run: mvn test -fae
run: mvn test -fae --no-transfer-progress
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kttdevelopment</groupId>
<artifactId>mal4j</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>

<profiles>
<profile>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/kttdevelopment/mal4j/APICall.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ else if(type == Field.class)
private final Map<String,String> headers = new HashMap<>();

// \{(.*?)\}
private static final Pattern pathArg = Pattern.compile("\\{(.*?)}");
@SuppressWarnings("RegExpRedundantEscape") // android requires this syntax (#133)
private static final Pattern pathArg = Pattern.compile("\\{(.*?)\\}");

private final Map<String,String> pathVars = new HashMap<>();
private final Map<String,String> queries = new HashMap<>();
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/kttdevelopment/mal4j/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Json {
*/

// [\{\}\[\],]
private static final Pattern split = Pattern.compile("[{}\\[\\],]");
@SuppressWarnings("RegExpRedundantEscape") // android requires this syntax (#133)
private static final Pattern split = Pattern.compile("[\\{\\}\\[\\],]");

// (?<!\\)(?:\\\\)*"
private static final Pattern nonEscQuote = Pattern.compile("(?<!\\\\)(?:\\\\\\\\)*\"");
Expand All @@ -47,8 +48,9 @@ class Json {
private static final Function<MatchResult,String> unicodeReplacer = matchResult -> String.valueOf((char) Integer.parseInt(matchResult.group(1), 16));

// \\"|\\\/|\\\\
@SuppressWarnings("RegExpRedundantEscape") // android requires this syntax (#133)
private static final Pattern escapedCharacters =
Pattern.compile("\\\\\"|\\\\/|\\\\\\\\");
Pattern.compile("\\\\\"|\\\\\\/|\\\\\\\\");

private static final Function<MatchResult,String> escapedReplacer = matchResult -> {
final String chars = matchResult.group(0);
Expand All @@ -68,8 +70,9 @@ class Json {
private static final Pattern mapType =
Pattern.compile("^\\s*(?<!\\\\)\"(?<key>.+(?<!\\\\)(?:\\\\\\\\)*)\": ?((?<double>-?\\d+\\.\\d+) *,?|(?<int>-?\\d+) *,?|(?<boolean>\\Qtrue\\E|\\Qfalse\\E) *,?|(?<null>\\Qnull\\E) *,?|(?<!\\\\)\"(?<string>.*(?<!\\\\)(?:\\\\\\\\)*)\" *,?|(?<array>\\[)|(?<map>\\{))\\s*$");
// ^\s*} *,?\s*$
@SuppressWarnings("RegExpRedundantEscape") // android requires this syntax (#133)
private static final Pattern mapClose =
Pattern.compile("^\\s*} *,?\\s*$");
Pattern.compile("^\\s*\\} *,?\\s*$");

// ^\s*((?<double>-?\d+\.\d+) *,?|(?<int>-?\d+) *,?|(?<boolean>\Qtrue\E|\Qfalse\E) *,?|(?<null>\Qnull\E) *,?|(?<!\\)"(?<string>.*(?<!\\)(?:\\\\)*)" *,?|(?<array>\[)|(?<map>\{))\s*$
private static final Pattern arrType =
Expand Down

0 comments on commit 6faaedf

Please sign in to comment.