Skip to content

Commit 22a434c

Browse files
committed
quote backslashes in regex patterns
1 parent 2e9f676 commit 22a434c

6 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/g2html/Config.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.net.URLEncoder;
88
import java.nio.file.Path;
99
import java.util.List;
10+
import java.util.regex.Pattern;
1011

1112
public class Config {
1213
// default subdirectory names in the result
@@ -71,7 +72,7 @@ public static void load(String[] args) {
7172

7273
// returns the input dot file for a given C file, and function
7374
public static File getFunDotFile(String path, String fun) {
74-
path = path.replaceAll(File.separator,"%2F");
75+
path = path.replaceAll(Pattern.quote(File.separator),"%2F");
7576
File f = new File(new File(new File(conf.getCfgDir()), path), fun + ".dot");
7677
return f;
7778
}

src/g2html/Loc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.*;
55
import java.net.URLEncoder;
66
import java.util.logging.Logger;
7+
import java.util.regex.Pattern;
78

89
public class Loc {
910

@@ -17,7 +18,7 @@ static public void parseLocNode(XMLStreamReader parser, Result res, ResultStats
1718
String id = parser.getAttributeValue("", "id");
1819

1920
// compute the file-id from the full path
20-
String shortFile = file.replaceAll(File.separator,"%2F");
21+
String shortFile = file.replaceAll(Pattern.quote(File.separator),"%2F");
2122

2223
// look up the database for the file
2324
FileStats fileStats = resultStats.getStats(shortFile);

src/g2html/Result.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.*;
44
import java.nio.channels.FileChannel;
5+
import java.util.regex.Pattern;
56

67
// handles the result directory structure
78
public class Result {
@@ -103,7 +104,7 @@ public Result(String resDir) throws IOException {
103104

104105
// return a listing file to be created
105106
public File getListingFile(String path) {
106-
path = path.replaceAll(File.separator,"%2F");
107+
path = path.replaceAll(Pattern.quote(File.separator),"%2F");
107108
File f = new File(filDir, path+".xml");
108109
return f;
109110
}

src/g2html/ResultStats.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.Map;
1212
import java.util.Set;
1313
import java.util.TreeMap;
14+
import java.util.regex.Matcher;
15+
import java.util.regex.Pattern;
1416

1517
// result stats encapsulates all databases for all files
1618
public class ResultStats {
@@ -57,7 +59,7 @@ public void printReport(Result r)
5759
continue;
5860
// write the file-name
5961
report.writeStartElement("file");
60-
report.writeAttribute("name", file.replaceAll("%2F",File.separator));
62+
report.writeAttribute("name", file.replaceAll("%2F", Matcher.quoteReplacement(File.separator)));
6163

6264
// for each function
6365
for (String fun : fm.get(file).getFunctions()){

src/g2html/Structure.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
import java.io.File;
77
import java.io.UnsupportedEncodingException;
88
import java.net.URLEncoder;
9+
import java.util.regex.Pattern;
910

1011
public class Structure {
1112
// read the structure from the xml and store it in the databases
1213
public static void parseFileNode(XMLStreamReader parser, ResultStats resultStats)
1314
throws XMLStreamException {
1415

1516
// get basic information
16-
String name = parser.getAttributeValue("", "path").replaceAll(File.separator,"%2F");;
17+
String name = parser.getAttributeValue("", "path").replaceAll(Pattern.quote(File.separator),"%2F");;
1718
String fun = "";
1819

1920
// parse the file and

src/g2html/Warning.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.FileNotFoundException;
66
import java.io.FileOutputStream;
77
import java.util.logging.Logger;
8+
import java.util.regex.Pattern;
89

910
public class Warning {
1011
private static int counter = 1;
@@ -43,7 +44,7 @@ static public void parseWarningNode(XMLStreamReader parser, Result res, ResultSt
4344
readcc.getLocalName()=="text"){
4445
String path = readcc.getAttributeValue("","file");
4546
String line = readcc.getAttributeValue("","line");
46-
String shortFile = path.replaceAll(File.separator,"%2F");;
47+
String shortFile = path.replaceAll(Pattern.quote(File.separator),"%2F");;
4748

4849
resultStats.getStats(shortFile).addWarning(id,Integer.valueOf(line));
4950
}

0 commit comments

Comments
 (0)