Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #37 from mobify/add-utf8-charset

Fixes problems loading scripts from preview on non-UTF8 pages.
  • Loading branch information...
commit e3f3b1360a9936a5b65ae54a8231de94e2716a73 2 parents a431794 + 75b091a
@johnboxall johnboxall authored
View
15 src/preview.coffee
@@ -2,7 +2,7 @@ Events = require 'events'
FS = require 'fs'
Http = require 'http'
Path = require 'path'
-URL = require 'url'
+Url = require 'url'
Request = require 'request'
Express = require 'express'
@@ -15,9 +15,12 @@ errorTemplate = require '../lib/errorTemplate.js'
MimeTypes =
- 'css': 'text/css'
- 'html': 'text/html'
- 'js': 'application/javascript'
+ 'css': 'text/css; charset=utf8'
+ 'html': 'text/html; charset=utf8'
+ 'xml': 'application/xml; charset=utf8'
+ 'xhtml': 'application/xhtml+xml; charset=utf8'
+ 'js': 'application/javascript; charset=utf8'
+ 'json': 'application/json; charset=utf8'
'jpeg': 'image/jpeg'
'jpg': 'image/jpeg'
'png': 'image/png'
@@ -39,7 +42,7 @@ class PreviewHandler
get: (request, response) =>
request.on "end", =>
- url = URL.parse request.url
+ url = Url.parse request.url
path = url.pathname.slice 1
ext = Utils.getExt path
@@ -70,7 +73,7 @@ class PreviewHandler
buf += chunk
request.on "end", =>
- url = URL.parse request.url
+ url = Url.parse request.url
path = url.pathname.slice 1
headers = {"Content-Type": "text/plain"}
View
37 test/fixtures-shiftjis/index.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Shift-JIS Test</title>
+<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
+<!--
+ Usage:
+
+ 1. Run `mobify preview` in this folder.
+ 2. Open this page.
+ 3. Ensure the characters look correct.
+-->
+<script>
+(function(window, document, mjs) {
+
+window.Mobify = {points: [+new Date], tagVersion: [1, 0]};
+
+document.write('<plaintext style="display:none">');
+
+setTimeout(function() {
+ var mobifyjs = document.createElement('script')
+ , script = document.getElementsByTagName('script')[0];
+
+ mobifyjs.src = mjs;
+ script.parentNode.insertBefore(mobifyjs, script);
+});
+
+})(this, document, 'http://127.0.0.1:8080/mobify.js');
+</script>
+</head>
+<body>
+<p>This file is encoded using SHIFT-JIS.</p>
+<p>All the lines below should look the same.</p>
+<h1>TEST: ‚ǁ[‚à</h1>
+<h1>REPLACE</h1>
+</body>
+</html>
View
9 test/fixtures-shiftjis/project.json
@@ -0,0 +1,9 @@
+{
+ "name": "tester",
+ "api": "1.1",
+ "build_directory": "bld",
+ "plugins": [],
+ "exclude": [
+ "*.tmpl"
+ ]
+}
View
13 test/fixtures-shiftjis/src/mobify.konf
@@ -0,0 +1,13 @@
+{>"/base/lib/base_konf.konf"/}
+
+{<tmpl}{/tmpl}
+
+{<konf} {
+
+'OUTPUTHTML': function(context) {
+ var outerHtml = context.data("$html")[0].outerHTML
+ outerHtml = outerHtml.replace(/REPLACE/, "UTF8: どーも");
+ return outerHtml;
+}
+
+} {/konf}
Please sign in to comment.
Something went wrong with that request. Please try again.