Skip to content

Commit a1b18c4

Browse files
Encode with UTF-8 if getString has funny characters
1 parent 276cbd1 commit a1b18c4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

java/src/main/java/com/genexus/internet/HttpClientJavaLib.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,23 +724,16 @@ public String getString() {
724724
return "";
725725
try {
726726
this.setEntity();
727-
ContentType contentType = ContentType.getOrDefault(entity);
728-
Charset charset;
729-
if (contentType.equals(ContentType.DEFAULT_TEXT)) {
730-
charset = StandardCharsets.UTF_8;
731-
} else {
732-
charset = contentType.getCharset();
733-
if (charset == null) {
734-
charset = StandardCharsets.UTF_8;
735-
}
736-
}
727+
Charset charset = ContentType.getOrDefault(entity).getCharset();
737728
String res = EntityUtils.toString(entity, charset);
729+
if (res.matches(".*[Ã-ÿ].*")) {
730+
res = EntityUtils.toString(entity, StandardCharsets.UTF_8);
731+
}
738732
eof = true;
739733
return res;
740734
} catch (IOException e) {
741735
setExceptionsCatch(e);
742-
} catch (IllegalArgumentException e) {
743-
}
736+
} catch (IllegalArgumentException e) {}
744737
return "";
745738
}
746739

0 commit comments

Comments
 (0)