diff --git a/src/etc/testcases/filters/expected/stripjavacomments.test b/src/etc/testcases/filters/expected/stripjavacomments.test index 53c7137b2..c8d0672a2 100644 --- a/src/etc/testcases/filters/expected/stripjavacomments.test +++ b/src/etc/testcases/filters/expected/stripjavacomments.test @@ -14,6 +14,6 @@ public class NormalLine { } private String url = "http://ant.apache.org/"; - private String url2 = "\"http://ant.apache.org/\""; + private String url2 = "\"http://ant.apache.org/\""; } diff --git a/src/main/org/apache/tools/ant/filters/StripJavaComments.java b/src/main/org/apache/tools/ant/filters/StripJavaComments.java index 829d39065..9da58d59e 100644 --- a/src/main/org/apache/tools/ant/filters/StripJavaComments.java +++ b/src/main/org/apache/tools/ant/filters/StripJavaComments.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -80,6 +80,11 @@ public final class StripJavaComments */ private boolean inString = false; + /** + * Whether or not the last char has been a backslash. + */ + private boolean quoted = false; + /** * Constructor for "dummy" instances. * @@ -116,9 +121,13 @@ public final class StripJavaComments readAheadCh = -1; } else { ch = in.read(); - if (ch == '"') { + if (ch == '"' && !quoted) { inString = !inString; + quoted = false; + } else if (ch == '\\') { + quoted = !quoted; } else { + quoted = false; if (!inString) { if (ch == '/') { ch = in.read();