Name: ssR10000 Date: 01/25/2001
The Pattern.compile() method incorrectly parses octal sequences.
The root of problem in "private int o()" method.
It parses correctly only two digit octal sequences, but JavaDoc says:
\0n The character with octal value 0n (0 <= n <= 7)
\0nn The character with octal value 0nn (0 <= n <= 7)
\0mnn The character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7)
See example for more info.
---------------------- example ---------------------
import java.util.regex.*;
public class Test {
public static void main(String argv[]) {
System.out.println("Test \\07 pattern...");
String pattern = "\\o7";
try {
Pattern res = Pattern.compile(pattern);
} catch(PatternSyntaxException e) {
System.out.println("Pattern : " + pattern);
System.out.println("Unexpected exception : " + e);
}
System.out.println("Test \\0007 pattern...");
pattern = "\\o007";
try {
Pattern res = Pattern.compile(pattern);
boolean match = Pattern.matches(pattern, "\\u0007");
if (match) {
System.out.println("OK. Pattern : " + pattern);
} else {System.out.println("Not OK.");}
} catch(PatternSyntaxException e) {
System.out.println("Pattern : " + pattern);
System.out.println("Unexpected exception : " + e);
}
System.exit(0);
}
}
---------------------- output ----------------------
Test \07 pattern...
Pattern : \07
Unexpected exception : java.util.regex.PatternSyntaxException: illegal octal escape sequence around index 4
\07
^
Test \0007 pattern...
Not OK.
----------------------------------------------------
======================================================================