Browse Source

ConfigFile now escapes #

git-svn-id: http://svn.dmdirc.com/trunk@3789 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
0e47e54b08
2 changed files with 24 additions and 2 deletions
  1. 3
    2
      src/com/dmdirc/util/ConfigFile.java
  2. 21
    0
      test/com/dmdirc/util/ConfigFileTest.java

+ 3
- 2
src/com/dmdirc/util/ConfigFile.java View File

@@ -293,14 +293,15 @@ public class ConfigFile {
293 293
     
294 294
     /**
295 295
      * Escapes the specified input string by prefixing all occurances of
296
-     * \, \n, \r, = and : with backslashes.
296
+     * \, \n, \r, =, # and : with backslashes.
297 297
      * 
298 298
      * @param input The string to be escaped
299 299
      * @return A backslash-armoured version of the string
300 300
      */
301 301
     protected static String escape(final String input) {
302 302
         return input.replaceAll("\\\\", "\\\\\\\\").replaceAll("\n", "\\\\n")
303
-                .replaceAll("\r", "\\\\r").replaceAll("=", "\\\\=").replaceAll(":", "\\\\:");
303
+                .replaceAll("\r", "\\\\r").replaceAll("=", "\\\\=")
304
+                .replaceAll(":", "\\\\:").replaceAll("#", "\\\\#");
304 305
     }
305 306
     
306 307
     /**

+ 21
- 0
test/com/dmdirc/util/ConfigFileTest.java View File

@@ -190,6 +190,27 @@ public class ConfigFileTest extends junit.framework.TestCase {
190 190
         assertEquals("hello", data.get("test3\\"));
191 191
     }
192 192
     
193
+    @Test
194
+    public void testHash() throws IOException, InvalidConfigFileException {
195
+        final File file = File.createTempFile("DMDirc.unittest", null);
196
+        ConfigFile config = new ConfigFile(file.toURI());
197
+        Map<String, String> data = new HashMap<String, String>();
198
+        data.put("test1#", "hello");
199
+        data.put("#test2", "hello");
200
+        data.put("test3", "#hello");
201
+        config.addDomain("test", data);
202
+        config.write();
203
+        
204
+        config = new ConfigFile(file.toURI());
205
+        config.read();
206
+        
207
+        assertTrue(config.isKeyDomain("test"));
208
+        data = config.getKeyDomain("test");
209
+        assertEquals("hello", data.get("test1#"));
210
+        assertEquals("hello", data.get("#test2"));
211
+        assertEquals("#hello", data.get("test3"));
212
+    }    
213
+    
193 214
     @Test
194 215
     public void testEscape() {
195 216
         final String input = "blah blah\\foo\r\nbar=:";

Loading…
Cancel
Save