From 6ccae0cd3313e135bd9f6e6634f56821ed2c2dfa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 2 Sep 2018 23:00:39 -0400 Subject: [PATCH] better unicode handling - fixes #347, i think --- src/middleware.ts | 3 ++- test/app/routes/fünke.html | 12 +++++++++++- test/app/routes/fünke.json.js | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/app/routes/fünke.json.js diff --git a/src/middleware.ts b/src/middleware.ts index 171481d..15b4bbf 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -185,7 +185,8 @@ function serve({ prefix, pathname, cache_control }: { const type = lookup(req.path); try { - const data = read(req.path.slice(1)); + const file = decodeURIComponent(req.path.slice(1)); + const data = read(file); res.setHeader('Content-Type', type); res.setHeader('Cache-Control', cache_control); diff --git a/test/app/routes/fünke.html b/test/app/routes/fünke.html index 088a7aa..e1fba6c 100644 --- a/test/app/routes/fünke.html +++ b/test/app/routes/fünke.html @@ -1 +1,11 @@ -

I'm afraid I just blue myself

\ No newline at end of file +

{phrase}

+ + \ No newline at end of file diff --git a/test/app/routes/fünke.json.js b/test/app/routes/fünke.json.js new file mode 100644 index 0000000..a9ccd6e --- /dev/null +++ b/test/app/routes/fünke.json.js @@ -0,0 +1,9 @@ +export function get(req, res) { + res.writeHead(200, { + 'Content-Type': 'application/json' + }); + + res.end(JSON.stringify( + "I'm afraid I just blue myself" + )); +} \ No newline at end of file