nginx-java-parser
nginx-java-parser copied to clipboard
Failure to parse location directive with character group with ' or "
I'm parsing a bunch of real world nginx configs and am encountering parsing failure if a character group in a location contains single and/or double quotes as characters. Probably they are treated in a special way in the grammar but I haven't figured it out yet how to fix it.
Here's a small self-contained example:
public class Test
{
public static void main(String[] args) throws IOException
{
String cfg = "server {\n" + //
" listen 80;\n" + //
" location ~ ^/([^/?&:']+)/ {\n" + //
" }\n" + //
"}";
NgxConfig.read(new ByteArrayInputStream(cfg.getBytes()));
}
}
Output:
line 3:22 token recognition error at: '']+)/ {\n }\n}'
line 3:15 mismatched input '(' expecting '{'
The same thing happens with double quotes:
public class Test
{
public static void main(String[] args) throws IOException
{
String cfg = "server {\n" + //
" listen 80;\n" + //
" location ~ ^/([^/?&:\"]+)/ {\n" + //
" }\n" + //
"}";
NgxConfig.read(new ByteArrayInputStream(cfg.getBytes()));
}
}
Output:
line 3:22 token recognition error at: '"]+)/ {\n }\n}'
line 3:15 mismatched input '(' expecting '{'
Here are the config files as plain text, so that they can be used as test cases. It also makes sense to have a test case with both single and double quotes:
server {
listen 80;
location ~ ^/([^/?&:']+)/ {
}
}
server {
listen 80;
location ~ ^/([^/?&:"]+)/ {
}
}
server {
listen 80;
location ~ ^/([^/?&:'"]+)/ {
}
}