Skip to content

Commit

Permalink
Fix #53
Browse files Browse the repository at this point in the history
This puts through a simple fix for escaping strings.  Basically, a string
literal which contained escaped characters was not being properly escaped when
printed.
  • Loading branch information
DavePearce committed Oct 6, 2020
1 parent fb8dc91 commit c3aa756
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/wyjs/io/JavaScriptFilePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ private void writeArrayLength(int indent, JavaScriptFile.ArrayLength term) {
private void writeConstant(JavaScriptFile.Constant term) {
Object value = term.getValue();
if(value instanceof String) {
String s = (String) value;
out.print("\"");
out.print(term.getValue());
out.print(s.replace("\"","\\\"").replace("\n","\\n").replace("\t","\\t"));
out.print("\"");
} else if(value instanceof Byte){
byte b = (Byte) value;
Expand Down
7 changes: 7 additions & 0 deletions tests/valid/JsString_Valid_17.whiley
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import string from js::core

public export method test():
// generate normal string
string s = "hello\n\t\"hello\""
//
assert s == "hello\n\t\"hello\""

0 comments on commit c3aa756

Please sign in to comment.