Skip to content

Commit 2270719

Browse files
committed
{WIP, NOK} attempt, but failed, to fix double escaping problem (#92)
1 parent 33bf22b commit 2270719

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

api/src/main/typescript/observable-wrapper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Minecraft {
2525

2626
runCommand(code: string, command: string): Observable<void> {
2727
return Observable.create(observer => {
28-
this.eb.send(this.address, {"code": code, "command": command}, {"action":"runCommand"}, this.handler(observer));
28+
this.eb.send(this.address, {"code": code, "command": this.escapeQuotes(command) }, {"action":"runCommand"}, this.handler(observer));
2929
});
3030
}
3131

@@ -46,6 +46,12 @@ export class Minecraft {
4646
};
4747
};
4848
}
49+
50+
private escapeQuotes(text: string): string {
51+
// see https://github.com/vorburger/minecraft-storeys-maker/issues/92
52+
// TODO find the right expression and then replace it with text.replace(new RegExp(..., 'g'), '\\"');
53+
return text.replace('\"', '\\"');
54+
}
4955
}
5056

5157
export enum HandType {

web/src/test/java/ch/vorburger/minecraft/storeys/web/SeleniumTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,19 @@ public void e_testNegativeAPI() {
159159
}
160160

161161
@Test
162-
public void e_testPositiveAPI() {
162+
public void f_testPositiveAPI() {
163163
testMinecraft.itemsHeld.put(HandType.MainHand, ItemType.Apple);
164164
assertThat(runTesterJSAndGetFailures().isEmpty());
165165
}
166166

167+
@Test
168+
public void g_testEncoding() {
169+
// Test encoding problems, see https://github.com/vorburger/minecraft-storeys-maker/issues/92
170+
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...\"]}}";
171+
testEventBusCall("minecraftCommand", nonTrivialCommand);
172+
assertThat(testMinecraft.ranCommands).contains(nonTrivialCommand);
173+
}
174+
167175
// TODO testWhenCommand
168176

169177
// TODO testAllOtherBlocks...

0 commit comments

Comments
 (0)