mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-30 13:38:30 +00:00
fix: android PathParser crash app if pass some wrong d prop (#2308)
Closes #2086 # Summary The application crashes if an error is thrown when something goes wrong during path parse. ## Test Plan You can easily check in that component `Test2086` how it works after the fix. ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ |
This commit is contained in:
@@ -62,7 +62,7 @@ class PathParser {
|
||||
|
||||
if (!has_prev_cmd && first_char != 'M' && first_char != 'm') {
|
||||
// The first segment must be a MoveTo.
|
||||
throw new Error(String.format("Unexpected character '%c' (i=%d, s=%s)", first_char, i, s));
|
||||
throw new IllegalArgumentException(String.format("Unexpected character '%c' (i=%d, s=%s)", first_char, i, s));
|
||||
}
|
||||
|
||||
// TODO: simplify
|
||||
@@ -75,7 +75,7 @@ class PathParser {
|
||||
} else if (is_number_start(first_char) && has_prev_cmd) {
|
||||
if (prev_cmd == 'Z' || prev_cmd == 'z') {
|
||||
// ClosePath cannot be followed by a number.
|
||||
throw new Error(String.format("Unexpected number after 'z' (s=%s)", s));
|
||||
throw new IllegalArgumentException(String.format("Unexpected number after 'z' (s=%s)", s));
|
||||
}
|
||||
|
||||
if (prev_cmd == 'M' || prev_cmd == 'm') {
|
||||
@@ -93,7 +93,7 @@ class PathParser {
|
||||
cmd = prev_cmd;
|
||||
}
|
||||
} else {
|
||||
throw new Error(String.format("Unexpected character '%c' (i=%d, s=%s)", first_char, i, s));
|
||||
throw new IllegalArgumentException(String.format("Unexpected character '%c' (i=%d, s=%s)", first_char, i, s));
|
||||
}
|
||||
|
||||
boolean absolute = is_absolute(cmd);
|
||||
@@ -226,7 +226,8 @@ class PathParser {
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new Error(String.format("Unexpected comand '%c' (s=%s)", cmd, s));
|
||||
throw new IllegalArgumentException(String.format("Unexpected comand '%c' (s=%s)", cmd, s));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,8 +624,7 @@ class PathParser {
|
||||
c = s.charAt(i);
|
||||
}
|
||||
} else if (c != '.') {
|
||||
throw new Error(
|
||||
String.format("Invalid number formating character '%c' (i=%d, s=%s)", c, i, s));
|
||||
throw new IllegalArgumentException(String.format("Invalid number formating character '%c' (i=%d, s=%s)", c, i, s));
|
||||
}
|
||||
|
||||
// Consume fraction.
|
||||
@@ -649,8 +649,7 @@ class PathParser {
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
skip_digits();
|
||||
} else {
|
||||
throw new Error(
|
||||
String.format("Invalid number formating character '%c' (i=%d, s=%s)", c, i, s));
|
||||
throw new IllegalArgumentException(String.format("Invalid number formating character '%c' (i=%d, s=%s)", c, i, s));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -660,8 +659,7 @@ class PathParser {
|
||||
|
||||
// inf, nan, etc. are an error.
|
||||
if (Float.isInfinite(n) || Float.isNaN(n)) {
|
||||
throw new Error(
|
||||
String.format("Invalid number '%s' (start=%d, i=%d, s=%s)", num, start, i, s));
|
||||
throw new IllegalArgumentException(String.format("Invalid number '%s' (start=%d, i=%d, s=%s)", num, start, i, s));
|
||||
}
|
||||
|
||||
return n;
|
||||
|
||||
Reference in New Issue
Block a user