Skip to content

Commit 6bbafd4

Browse files
committed
ff: Escaping quotes in preferences. Fixes issue 8273
1 parent 1ec882e commit 6bbafd4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: java/client/src/org/openqa/selenium/firefox/Preferences.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class Preferences {
4646
*/
4747
private static final String MAX_SCRIPT_RUN_TIME_KEY = "dom.max_script_run_time";
4848
private static final int DEFAULT_MAX_SCRIPT_RUN_TIME = 30;
49-
49+
5050
/**
5151
* This pattern is used to parse preferences in user.js. It is intended to match all preference
5252
* lines in the format generated by Firefox; it won't necessarily match all possible lines that
5353
* Firefox will parse.
54-
*
54+
*
5555
* e.g. if you have a line with extra spaces after the end-of-line semicolon, this pattern will
5656
* not match that line because Firefox never generates lines like that.
5757
*/
@@ -172,17 +172,22 @@ public void addTo(FirefoxProfile profile) {
172172
public void writeTo(Writer writer) throws IOException {
173173
for (Map.Entry<String, Object> pref : allPrefs.entrySet()) {
174174
writer.append("user_pref(\"").append(pref.getKey()).append("\", ");
175-
writer.append(valueAsPreference(pref.getValue()).replaceAll("\\\\", "\\\\\\\\"));
175+
writer.append(valueAsPreference(pref.getValue()));
176176
writer.append(");\n");
177177
}
178178
}
179179

180180
private String valueAsPreference(Object value) {
181181
if (value instanceof String) {
182-
return "\"" + value + "\"";
182+
return "\"" + escapeValueAsPreference((String) value) + "\"";
183+
} else {
184+
return escapeValueAsPreference(String.valueOf(value));
183185
}
184186

185-
return String.valueOf(value);
187+
}
188+
189+
private String escapeValueAsPreference(String value) {
190+
return value.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\"");
186191
}
187192

188193
private Object preferenceAsValue(String toConvert) {

0 commit comments

Comments
 (0)