commit 4598dc1cf3b79fad2da64b60f9ac97bbcdea24b7
Author: Simon Legner <Simon.Legner@gmail.com>
Date: Fri Jan 10 19:13:28 2014 +0100
fix #9560 - IllegalArgumentException when color.layer contains "{ }"
diff --git a/src/org/openstreetmap/josm/data/Preferences.java b/src/org/openstreetmap/josm/data/Preferences.java
index ac199d6..7680dc4 100644
a
|
b
|
import org.openstreetmap.josm.io.MirroredInputStream;
|
52 | 52 | import org.openstreetmap.josm.io.XmlWriter; |
53 | 53 | import org.openstreetmap.josm.tools.CheckParameterUtil; |
54 | 54 | import org.openstreetmap.josm.tools.ColorHelper; |
| 55 | import org.openstreetmap.josm.tools.I18n; |
55 | 56 | import org.openstreetmap.josm.tools.Utils; |
56 | 57 | |
57 | 58 | /** |
… |
… |
public class Preferences {
|
835 | 836 | try { |
836 | 837 | Matcher m = Pattern.compile("mappaint\\.(.+?)\\.(.+)").matcher(o); |
837 | 838 | if (m.matches()) { |
838 | | return tr("Paint style {0}: {1}", tr(m.group(1)), tr(m.group(2))); |
| 839 | return tr("Paint style {0}: {1}", tr(I18n.escape(m.group(1))), tr(I18n.escape(m.group(2)))); |
839 | 840 | } |
840 | 841 | } catch (Exception e) { |
841 | 842 | Main.warn(e); |
… |
… |
public class Preferences {
|
843 | 844 | try { |
844 | 845 | Matcher m = Pattern.compile("layer (.+)").matcher(o); |
845 | 846 | if (m.matches()) { |
846 | | return tr("Layer: {0}", tr(m.group(1))); |
| 847 | return tr("Layer: {0}", tr(I18n.escape(m.group(1)))); |
847 | 848 | } |
848 | 849 | } catch (Exception e) { |
849 | 850 | Main.warn(e); |
850 | 851 | } |
851 | | return tr(colornames.containsKey(o) ? colornames.get(o) : o); |
| 852 | return tr(I18n.escape(colornames.containsKey(o) ? colornames.get(o) : o)); |
852 | 853 | } |
853 | 854 | |
854 | 855 | /** |
diff --git a/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy b/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy
new file mode 100644
index 0000000..acd8f4b
-
|
+
|
|
| 1 | package org.openstreetmap.josm.data |
| 2 | |
| 3 | import org.openstreetmap.josm.Main |
| 4 | |
| 5 | class PreferencesTest extends GroovyTestCase { |
| 6 | @Override |
| 7 | void setUp() { |
| 8 | Main.initApplicationPreferences() |
| 9 | } |
| 10 | |
| 11 | void testColorName() { |
| 12 | Main.pref.getColorName("color.layer {5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx") == "{5DE308C0-916F-4B5A-B3DB-D45E17F30172}.gpx" |
| 13 | } |
| 14 | } |
diff --git a/test/unit/org/openstreetmap/josm/tools/I18nTest.groovy b/test/unit/org/openstreetmap/josm/tools/I18nTest.groovy
new file mode 100644
index 0000000..96c5bd5
-
|
+
|
|
| 1 | // License: GPL. For details, see LICENSE file. |
| 2 | package org.openstreetmap.josm.tools |
| 3 | |
| 4 | class I18nTest extends GroovyTestCase { |
| 5 | void testEscape() { |
| 6 | def foobar = "{foo'bar}" |
| 7 | assert I18n.escape(foobar) == "'{'foo''bar'}'" |
| 8 | assert I18n.tr(I18n.escape(foobar)) == foobar |
| 9 | } |
| 10 | } |