Skip to content

Commit 902dabd

Browse files
committed
JShellWrapper changed the way \n is managed
1 parent 498f50d commit 902dabd

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

JShellAPI/src/main/java/org/togetherjava/jshellapi/service/JShellService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private JShellResult readResult() throws IOException, NumberFormatException, Doc
9999
SnippetStatus status = Utils.nameOrElseThrow(SnippetStatus.class, reader.readLine(), name -> new DockerException(name + " isn't an enum constant"));
100100
SnippetType type = Utils.nameOrElseThrow(SnippetType.class, reader.readLine(), name -> new DockerException(name + " isn't an enum constant"));
101101
int snippetId = Integer.parseInt(reader.readLine());
102-
String source = desanitize(reader.readLine());
102+
String source = cleanCode(reader.readLine());
103103
String result = reader.readLine().transform(r -> r.equals("NONE") ? null : r);
104104
snippetResults.add(new JShellSnippetResult(status, type, snippetId, source, result));
105105
}
@@ -123,8 +123,8 @@ private JShellResult readResult() throws IOException, NumberFormatException, Doc
123123
case "SYNTAX_ERROR" -> new JShellEvalAbortionCause.SyntaxErrorAbortionCause();
124124
default -> throw new DockerException("Abortion cause " + rawAbortionCause + " doesn't exist");
125125
};
126-
String causeSource = reader.readLine();
127-
String remainingSource = reader.readLine();
126+
String causeSource = cleanCode(reader.readLine());
127+
String remainingSource = cleanCode(reader.readLine());
128128
abortion = new JShellEvalAbortion(causeSource, remainingSource, abortionCause);
129129
}
130130
boolean stdoutOverflow = Boolean.parseBoolean(reader.readLine());
@@ -149,7 +149,7 @@ public Optional<List<String>> snippets() throws DockerException {
149149
List<String> snippets = new ArrayList<>();
150150
String snippet;
151151
while(!(snippet = reader.readLine()).isEmpty()) {
152-
snippets.add(desanitize(snippet));
152+
snippets.add(cleanCode(snippet));
153153
}
154154
return Optional.of(snippets);
155155
} catch (IOException ex) {
@@ -251,5 +251,8 @@ private static String sanitize(String s) {
251251
private static String desanitize(String text) {
252252
return text.replace("\\n", "\n").replace("\\\\", "\\");
253253
}
254+
private static String cleanCode(String code) {
255+
return code.translateEscapes();
256+
}
254257

255258
}

0 commit comments

Comments
 (0)