Skip to content

Commit

Permalink
{WIP, NOK} attempt, but failed, to fix double escaping problem (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Aug 20, 2018
1 parent 33bf22b commit 2270719
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion api/src/main/typescript/observable-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Minecraft {

runCommand(code: string, command: string): Observable<void> {
return Observable.create(observer => {
this.eb.send(this.address, {"code": code, "command": command}, {"action":"runCommand"}, this.handler(observer));
this.eb.send(this.address, {"code": code, "command": this.escapeQuotes(command) }, {"action":"runCommand"}, this.handler(observer));
});
}

Expand All @@ -46,6 +46,12 @@ export class Minecraft {
};
};
}

private escapeQuotes(text: string): string {
// see https://github.com/vorburger/minecraft-storeys-maker/issues/92
// TODO find the right expression and then replace it with text.replace(new RegExp(..., 'g'), '\\"');
return text.replace('\"', '\\"');
}
}

export enum HandType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,19 @@ public void e_testNegativeAPI() {
}

@Test
public void e_testPositiveAPI() {
public void f_testPositiveAPI() {
testMinecraft.itemsHeld.put(HandType.MainHand, ItemType.Apple);
assertThat(runTesterJSAndGetFailures().isEmpty());
}

@Test
public void g_testEncoding() {
// Test encoding problems, see https://github.com/vorburger/minecraft-storeys-maker/issues/92
String nonTrivialCommand = "give michaelpapa7 written_book 1 0 {pages:[\"{\\\"text\\\":\\\"Hello\\\"}\"],title:\"First Quest\",author:\"https://www.learn.study\",display:{Lore:[\"The first quest is your first test...\"]}}";
testEventBusCall("minecraftCommand", nonTrivialCommand);
assertThat(testMinecraft.ranCommands).contains(nonTrivialCommand);
}

// TODO testWhenCommand

// TODO testAllOtherBlocks...
Expand Down

0 comments on commit 2270719

Please sign in to comment.