@@ -46,12 +46,12 @@ class Preferences {
46
46
*/
47
47
private static final String MAX_SCRIPT_RUN_TIME_KEY = "dom.max_script_run_time" ;
48
48
private static final int DEFAULT_MAX_SCRIPT_RUN_TIME = 30 ;
49
-
49
+
50
50
/**
51
51
* This pattern is used to parse preferences in user.js. It is intended to match all preference
52
52
* lines in the format generated by Firefox; it won't necessarily match all possible lines that
53
53
* Firefox will parse.
54
- *
54
+ *
55
55
* e.g. if you have a line with extra spaces after the end-of-line semicolon, this pattern will
56
56
* not match that line because Firefox never generates lines like that.
57
57
*/
@@ -172,17 +172,22 @@ public void addTo(FirefoxProfile profile) {
172
172
public void writeTo (Writer writer ) throws IOException {
173
173
for (Map .Entry <String , Object > pref : allPrefs .entrySet ()) {
174
174
writer .append ("user_pref(\" " ).append (pref .getKey ()).append ("\" , " );
175
- writer .append (valueAsPreference (pref .getValue ()). replaceAll ( " \\ \\ " , " \\ \\ \\ \\ " ) );
175
+ writer .append (valueAsPreference (pref .getValue ()));
176
176
writer .append (");\n " );
177
177
}
178
178
}
179
179
180
180
private String valueAsPreference (Object value ) {
181
181
if (value instanceof String ) {
182
- return "\" " + value + "\" " ;
182
+ return "\" " + escapeValueAsPreference ((String ) value ) + "\" " ;
183
+ } else {
184
+ return escapeValueAsPreference (String .valueOf (value ));
183
185
}
184
186
185
- return String .valueOf (value );
187
+ }
188
+
189
+ private String escapeValueAsPreference (String value ) {
190
+ return value .replaceAll ("\\ \\ " , "\\ \\ \\ \\ " ).replaceAll ("\" " , "\\ \\ \" " );
186
191
}
187
192
188
193
private Object preferenceAsValue (String toConvert ) {
0 commit comments