Skip to content

Commit 02049f5

Browse files
yoshito-umaokayumaoka
authored andcommitted
Fixed \uXXXX unescaping issue in earlier commit
And updated the test cases to include unicode escapes and others in comments, fix properties file encoding in eclipse workspace, etc.
1 parent 378961d commit 02049f5

12 files changed

Lines changed: 43 additions & 16 deletions

File tree

gp-res-filter/.settings/org.eclipse.core.resources.prefs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ eclipse.preferences.version=1
22
encoding//src/main/java=UTF-8
33
encoding//src/test/java=UTF-8
44
encoding//src/test/resource/resfilter/ios/write-output.strings=UTF-8
5+
encoding//src/test/resource/resfilter/utf8_properties/input.properties=UTF-8
6+
encoding//src/test/resource/resfilter/utf8_properties/merge-output.properties=UTF-8
7+
encoding//src/test/resource/resfilter/utf8_properties/parse-test-input.properties=UTF-8
8+
encoding//src/test/resource/resfilter/utf8_properties/parseline-test-input.properties=UTF-8
9+
encoding//src/test/resource/resfilter/utf8_properties/write-output.properties=UTF-8
510
encoding/<project>=UTF-8

gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/impl/JavaPropertiesResource.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,14 @@ public void print(PrintWriter pw, BreakIterator brkItr, boolean isUTF8) throws I
355355
// Write out any notes (comments) associated with this resource.
356356
if (notes != null) {
357357
for (String note : notes) {
358-
pw.println("#" + note);
358+
if (isUTF8) {
359+
pw.println("#" + note);
360+
} else {
361+
pw.println("#" + escapeOnlyUnicode(note));
362+
}
359363
}
360364
}
361-
365+
362366
if (len <= COLMAX) {
363367
// Print this property in a single line
364368
if (separator.getCharacter() == PropSeparator.SPACE.getCharacter()) {
@@ -688,7 +692,7 @@ private static String unescapeOnlyUnicode(String str) {
688692
final StringBuilder buf = new StringBuilder();
689693
for (int i = 0; i < str.length(); i++) {
690694
final char c = str.charAt(i);
691-
if (c == BACKSLASH && i + 5 >= str.length()) {
695+
if (c == BACKSLASH && i + 5 <= str.length()) {
692696
boolean isUniEsc = false;
693697
i++;
694698
final char c1 = str.charAt(i);

gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/impl/JavaPropertiesResourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class JavaPropertiesResourceTest {
100100
.sequenceNumber(11).notes(Arrays.asList(" Not a Java MessageFormat param")).build());
101101

102102
lst.add(ResourceString.with("backslashes", "a\\b\\c")
103-
.sequenceNumber(12).notes(Arrays.asList(" A comment with backslashes - a\\b\\c")).build());
103+
.sequenceNumber(12).notes(Arrays.asList(" A comment with backslashes - a\\b\\c あい \\t\\n")).build());
104104

105105
Collections.sort(lst, new ResourceStringComparator());
106106
EXPECTED_INPUT_RES_LIST = lst;
@@ -133,7 +133,7 @@ public class JavaPropertiesResourceTest {
133133
bundleBuilder.addResourceString("non-param", "This {} is not a parameter.", 11,
134134
Arrays.asList(" Not a Java MessageFormat param"));
135135
bundleBuilder.addResourceString("backslashes", "a\\b\\c", 12,
136-
Arrays.asList(" A comment with backslashes - a\\b\\c"));
136+
Arrays.asList(" A comment with backslashes - a\\b\\c あい \\t\\n"));
137137
bundleBuilder.addNotes(Arrays.asList(
138138
" You are reading the \".properties\" entry.",
139139
" The exclamation mark can also mark text as comments.",

gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/impl/JavaUTF8PropertiesResourceTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class JavaUTF8PropertiesResourceTest {
7878
.sequenceNumber(4)
7979
.notes(Arrays.asList(" Add spaces to the key")).build());
8080

81-
ResourceString rs5 = ResourceString.with("tab", "pick up the\u00A5 tab")
81+
ResourceString rs5 = ResourceString.with("tab", "pick up the ¥ tab")
8282
.sequenceNumber(5).addNote(" Unicode").build();
8383
lst.add(rs5);
8484

@@ -97,6 +97,9 @@ public class JavaUTF8PropertiesResourceTest {
9797
lst.add(ResourceString.with("参数1", "Value of parameter one").sequenceNumber(10)
9898
.notes(Arrays.asList(" Raw UTF8")).build());
9999

100+
lst.add(ResourceString.with("backslashes", "a\\b\\c").sequenceNumber(11)
101+
.notes(Arrays.asList(" A comment with backslashes - a\\b\\c あい \\t\\n")).build());
102+
100103
Collections.sort(lst, new ResourceStringComparator());
101104
EXPECTED_INPUT_RES_LIST = lst;
102105
}
@@ -113,7 +116,7 @@ public class JavaUTF8PropertiesResourceTest {
113116
bundleBuilder.addResourceString("message", "Translated - Welcome to Wikipedia!", 3,
114117
Arrays.asList(" The backslash below tells the application to continue reading",
115118
" the value onto the next line."));
116-
bundleBuilder.addResourceString("tab", "Translated - pick up the\u00A5 tab", 5,
119+
bundleBuilder.addResourceString("tab", "Translated - pick up the ¥ tab", 5,
117120
Arrays.asList(" Unicode"));
118121
bundleBuilder.addResourceString("leadSPs", "localized leading SPs", 6,
119122
Arrays.asList(" leading SPs"));
@@ -125,6 +128,9 @@ public class JavaUTF8PropertiesResourceTest {
125128
Arrays.asList(" tabs"));
126129
bundleBuilder.addResourceString("参数1", "localized Value of parameter one", 10,
127130
Arrays.asList(" Raw UTF8"));
131+
bundleBuilder.addResourceString("backslashes", "a\\b\\c", 11,
132+
Arrays.asList(" A comment with backslashes - a\\b\\c あい \\t\\n"));
133+
128134
bundleBuilder.addNotes(Arrays.asList(
129135
" You are reading the \".properties\" entry.",
130136
" The exclamation mark can also mark text as comments.",
@@ -142,11 +148,13 @@ public class JavaUTF8PropertiesResourceTest {
142148
EXPECTED_PROP_DEF_LIST.add(new PropDef("message", "Welcome to Wikipedia!", PropSeparator.COLON));
143149
EXPECTED_PROP_DEF_LIST.add(new PropDef("key with spaces",
144150
"This is the value that could be looked up with the key \"key with spaces\".", PropSeparator.EQUAL));
145-
EXPECTED_PROP_DEF_LIST.add(new PropDef("tab", "pick up the\u00A5 tab", PropSeparator.COLON));
151+
EXPECTED_PROP_DEF_LIST.add(new PropDef("tab", "pick up the ¥ tab", PropSeparator.COLON));
146152
EXPECTED_PROP_DEF_LIST.add(new PropDef("leadSPs", "leading SPs", PropSeparator.EQUAL));
147153
EXPECTED_PROP_DEF_LIST.add(new PropDef("leadTabs", "leading tabs", PropSeparator.EQUAL));
148154
EXPECTED_PROP_DEF_LIST.add(new PropDef("trailSPs", "trailing SPs ", PropSeparator.EQUAL));
149155
EXPECTED_PROP_DEF_LIST.add(new PropDef("withTabs", "Tab1\tTab2\tTab3\t", PropSeparator.EQUAL));
156+
EXPECTED_PROP_DEF_LIST.add(new PropDef("参数1", "Value of parameter one", PropSeparator.EQUAL));
157+
EXPECTED_PROP_DEF_LIST.add(new PropDef("backslashes", "a\\b\\c", PropSeparator.EQUAL));
150158
}
151159

152160
private static final JavaPropertiesResource res = new JavaPropertiesResource(Encoding.UTF_8, MessagePatternEscape.AUTO);

gp-res-filter/src/test/resource/resfilter/properties/input.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ withTabs = Tab1\tTab2\tTab3\t
2525
withQuote = You''re about to delete '{0}' rows in Mike''s file {0}.
2626
# Not a Java MessageFormat param
2727
non-param = This {} is not a parameter.
28-
# A comment with backslashes - a\b\c
28+
# A comment with backslashes - a\b\c \u3042\u3044 \t\n
2929
backslashes = a\\b\\c

gp-res-filter/src/test/resource/resfilter/properties/merge-output.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ withTabs = localized Tab1\tTab2\tTab3\t
2525
withQuote = You''re about to delete '{1}' rows in Mike''s file {0}.
2626
# Not a Java MessageFormat param
2727
non-param = This {} is not a parameter.
28-
# A comment with backslashes - a\b\c
28+
# A comment with backslashes - a\b\c \u3042\u3044 \t\n
2929
backslashes = a\\b\\c

gp-res-filter/src/test/resource/resfilter/properties/write-output.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ withTabs = localized Tab1\tTab2\tTab3\t
2626
withQuote = You''re about to delete '{1}' rows in Mike''s file {0}.
2727
# Not a Java MessageFormat param
2828
non-param = This {} is not a parameter.
29-
# A comment with backslashes - a\b\c
29+
# A comment with backslashes - a\b\c \u3042\u3044 \t\n
3030
backslashes = a\\b\\c

gp-res-filter/src/test/resource/resfilter/utf8_properties/input.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ message:Welcome to \
1212
# Add spaces to the key
1313
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
1414
# Unicode
15-
tab : pick up the\u00A5 tab
15+
tab : pick up the ¥ tab
1616
# leading SPs
1717
leadSPs = leading SPs
1818
# leading tabs
@@ -23,3 +23,5 @@ trailSPs = trailing SPs
2323
withTabs = Tab1\tTab2\tTab3\t
2424
# Raw UTF8
2525
参数1 = Value of parameter one
26+
# A comment with backslashes - a\b\c あい \t\n
27+
backslashes = a\\b\\c

gp-res-filter/src/test/resource/resfilter/utf8_properties/merge-output.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ message : Translated - Welcome to Wikipedia\!
1212
key\ with\ spaces = Translated - This is the value that could be looked up \
1313
with the key "key with spaces".
1414
# Unicode
15-
tab : Translated - pick up the¥ tab
15+
tab : Translated - pick up the ¥ tab
1616
# leading SPs
1717
leadSPs = localized leading SPs
1818
# leading tabs
@@ -23,3 +23,5 @@ trailSPs = localized trailing SPs
2323
withTabs = localized Tab1\tTab2\tTab3\t
2424
# Raw UTF8
2525
参数1 = localized Value of parameter one
26+
# A comment with backslashes - a\b\c あい \t\n
27+
backslashes = a\\b\\c

gp-res-filter/src/test/resource/resfilter/utf8_properties/parse-test-input.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ website = http\://en.wikipedia.org/
22
language English
33
message:Welcome to Wikipedia!
44
key\ with\ spaces=This is the value that could be looked up with the key "key with spaces".
5-
tab : pick up the\u00A5 tab
5+
tab : pick up the ¥ tab
66
leadSPs = leading SPs
77
leadTabs = leading tabs
88
trailSPs = trailing SPs
99
withTabs = Tab1\tTab2\tTab3\t
10+
参数1 = Value of parameter one
11+
backslashes = a\\b\\c

0 commit comments

Comments
 (0)