8000 fix issue #1361 by wendal · Pull Request #1362 · nutzam/nutz · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #1361 #1362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/org/nutz/ioc/impl/PropertiesProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void setPaths(String... paths) {
Streams.safeClose(bf);
}
}
putAll(p);
putAllTrim(p);
}
}
catch (IOException e) {
Expand Down
18 changes: 14 additions & 4 deletions src/org/nutz/lang/util/MultiLineProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
public class MultiLineProperties implements Map<String, String> {



public MultiLineProperties(Reader reader) throws IOException {
this();
load(reader);
Expand Down Expand Up @@ -89,7 +87,7 @@ public synchronized void load(Reader reader, boolean clear) throws IOException {
value = Strings.unicodeDecode(value);
}
value = value.replace("\\:", ":").replace("\\=", "=");
maps.put(Strings.trim(name), value);
putTrim(name, value);
} else if (c == ':') {
String name = s.substring(0, pos);
StringBuffer sb = new StringBuffer();
Expand All @@ -100,14 +98,18 @@ public synchronized void load(Reader reader, boolean clear) throws IOException {
break;
sb.append("\r\n" + ss);
}
maps.put(Strings.trim(name), sb.toString());
putTrim(name, sb.toString());
if (null == ss)
return;
} else {
maps.put(Strings.trim(s), null);
}
}
}

public void putTrim(String key, String value) {
maps.put(Strings.trim(key), Strings.trim(value));
}

public synchronized void clear() {
maps.clear();
Expand Down Expand Up @@ -151,11 +153,19 @@ public synchronized String put(String key, String value) {
return maps.put(key, value);
}


@SuppressWarnings({"unchecked", "rawtypes"})
public synchronized void putAll(Map t) {
maps.putAll(t);
}

@SuppressWarnings({"rawtypes"})
public synchronized void putAllTrim(Map t) {
for (Object key : t.keySet()) {
putTrim(Strings.sNull(key), Strings.sNull(t.get(key)));
}
}

public synchronized String remove(Object key) {
return maps.remove(key);
}
Expand Down
4 changes: 3 additions & 1 deletion test/config/conf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
str=Nutz
number=153
bool=1
chinese=\u575A\u679C
chinese=\u575A\u679C

ABC = 123
12 changes: 9 additions & 3 deletions test/org/nutz/ioc/impl/PropertiesProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testUTF8Properties() {

@Test
public void testString() throws UnsupportedEncodingException {
Assert.assertEquals("Nutz ", pp.get("str"));
Assert.assertEquals("Nutz", pp.get("str"));
Assert.assertEquals("Nutz", pp.getTrim("str"));
Assert.assertEquals("坚果", new String(pp.getTrim("chinese")));
}
Expand All @@ -55,7 +55,13 @@ public void testHas() {

@Test
public void testSize() {
Assert.assertEquals(pp.getKeys().size(), 4);
Assert.assertEquals(pp.getValues().size(), 4);
Assert.assertEquals(pp.getKeys().size(), 5);
Assert.assertEquals(pp.getValues().size(), 5);
}

@Test
public void testTrim() {
System.out.println(pp.get("ABC"));
Assert.assertEquals(123, pp.getInt("ABC"));
}
}
0