Skip to content

Commit afa5e79

Browse files
committed
Match url encoding with emrun url decoding in src/emrun_postjs.js. Fixes #3394. Add test.
1 parent 197fe0c commit afa5e79

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/emrun_postjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function emrun_register_handlers() {
1111
var prevErr = Module['printErr'];
1212
function emrun_exit() { post('^exit^'+EXITSTATUS); };
1313
Module['addOnExit'](emrun_exit);
14-
Module['print'] = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+text); prevPrint(text); }
15-
Module['printErr'] = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+text); prevErr(text); }
14+
Module['print'] = function emrun_print(text) { post('^out^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text)); prevPrint(text); }
15+
Module['printErr'] = function emrun_printErr(text) { post('^err^'+(emrun_http_sequence_number++)+'^'+encodeURIComponent(text)); prevErr(text); }
1616
}
1717
// Notify emrun web server that this browser has successfully launched the page.
1818
post('^pageload^');

tests/test_browser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ def test_emrun_info(self):
19671967
assert 'Traceback' not in result
19681968

19691969
def test_emrun(self):
1970-
Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world_exit.c'), '--emrun', '-o', 'hello_world.html']).communicate()
1970+
Popen([PYTHON, EMCC, path_from_root('tests', 'test_emrun.c'), '--emrun', '-o', 'hello_world.html']).communicate()
19711971
outdir = os.getcwd()
19721972
# We cannot run emrun from the temp directory the suite will clean up afterwards, since the browser that is launched will have that directory as startup directory,
19731973
# and the browser will not close as part of the test, pinning down the cwd on Windows and it wouldn't be possible to delete it. Therefore switch away from that directory
@@ -1985,6 +1985,8 @@ def test_emrun(self):
19851985
assert 'argc: 4' in stdout
19861986
assert 'argv[3]: --3' in stdout
19871987
assert 'hello, world!' in stdout
1988+
assert 'Testing ASCII characters: !"$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' in stdout
1989+
assert 'Testing char sequences: %20%21 &auml;' in stdout
19881990
assert 'hello, error stream!' in stderr
19891991

19901992
def test_uuid(self):

tests/test_emrun.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <emscripten.h>
4+
5+
int main(int argc, char **argv) {
6+
printf("argc: %d\n", argc);
7+
for(int i = 0; i < argc; ++i) {
8+
printf("argv[%d]: %s\n", i, argv[i]);
9+
}
10+
11+
// Dump a file to local filesystem with emrun.
12+
EM_ASM(emrun_file_dump("test.dat", HEAPU8.subarray(0, 128)););
13+
EM_ASM(emrun_file_dump("heap.dat", HEAPU8));
14+
15+
if (argc <= 1)
16+
exit(1);
17+
printf("hello, world!\n");
18+
fprintf(stderr, "hello, error stream!\n");
19+
20+
printf("Testing ASCII characters: !\"$%%&'()*+,-./:;<=>?@[\\]^_`{|}~\n");
21+
printf("Testing char sequences: %%20%%21 &auml;\n");
22+
23+
exit(100);
24+
}
25+

0 commit comments

Comments
 (0)