5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-05 06:12:25 +08:00

SQOOP-2562: Sqoop2: Should decode the key and value in MMapInput#restoreFromUrlSafeValueString

This commit is contained in:
Jarek Jarcec Cecho 2015-09-13 05:20:02 -07:00
parent 9f69badd96
commit c6047c4f2a
3 changed files with 15 additions and 5 deletions

View File

@ -48,7 +48,7 @@ public String getUrlSafeValueString() {
vsb.append("&");
}
vsb.append(UrlSafeUtils.urlEncode(entry.getKey())).append("=");
vsb.append(entry.getValue() != null ? UrlSafeUtils.urlEncode(entry.getValue()): null);
vsb.append(entry.getValue() != null ? UrlSafeUtils.urlEncode(entry.getValue()): "");
}
return vsb.toString();
}
@ -64,11 +64,14 @@ public void restoreFromUrlSafeValueString(String valueString) {
for (String pair : valuePairs) {
String[] nameAndVal = pair.split("=");
if (nameAndVal.length > 0) {
String name = nameAndVal[0];
String name = UrlSafeUtils.urlDecode(nameAndVal[0]);
String value = null;
if (nameAndVal.length > 1) {
value = nameAndVal[1];
}
if (value != null) {
value = UrlSafeUtils.urlDecode(value);
}
valueMap.put(name, value);
}

View File

@ -98,7 +98,7 @@ public void testUrlSafe() {
*/
@Test
public void testNamedElement() {
MStringInput input1 = new MStringInput("sqoopsqoop", true, InputEditable.ANY, StringUtils.EMPTY, (short) 5);
MMapInput input1 = new MMapInput("sqoopsqoop", true, InputEditable.ANY, StringUtils.EMPTY);
assertEquals("sqoopsqoop.label", input1.getLabelKey());
assertEquals("sqoopsqoop.help", input1.getHelpKey());
}

View File

@ -288,10 +288,13 @@ private static boolean fillInputMap(String prefix,
if (line.hasOption(opt)) {
String value = line.getOptionValue(opt);
Map<String, String> values = new HashMap<String, String>();
String[] keyValue = null;
String[] entries = value.split("&");
for (String entry : entries) {
if (entry.contains("=")) {
String[] keyValue = entry.split("=");
keyValue = entry.split("=", 2);
}
if (keyValue != null && keyValue.length == 2) {
values.put(keyValue[0], keyValue[1]);
} else {
errorMessage(input, "Don't know what to do with " + entry);
@ -757,7 +760,11 @@ private static boolean fillInputMapWithBundle(MMapInput input,
// try to remove entry that user specified.
if(userTyped.contains("=")) {
String []keyValue = userTyped.split("=", 2);
if (keyValue.length == 2) {
values.put(handleUserInput(keyValue[0]), handleUserInput(keyValue[1]));
} else {
errorMessage("Don't know what to do with " + userTyped);
}
} else {
String key = handleUserInput(userTyped);
if(values.containsKey(key)) {