Don't overly escape Meteor.settings.public

Fixes #3730.

Testing Done:
Manual testing based on the report in #3730. Also confirmed that `</script>` is not a problem.

I would have added a test-packages test but there's no easy way to override Meteor.settings in test-packages.

Bugs closed: 3730

Reviewed at https://rbcommons.com/s/meteor/r/1/
This commit is contained in:
David Glasser
2015-02-17 18:01:01 -08:00
parent 94683896b7
commit d4d349ca96
7 changed files with 21 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
{{#each css}} <link rel="stylesheet" type="text/css" class="__meteor-css__" href="{{../bundledJsCssPrefix}}{{url}}">{{/each}} {{#each css}} <link rel="stylesheet" type="text/css" class="__meteor-css__" href="{{../bundledJsCssPrefix}}{{url}}">{{/each}}
{{#if inlineScriptsAllowed}} {{#if inlineScriptsAllowed}}
<script type='text/javascript'>__meteor_runtime_config__ = {{meteorRuntimeConfig}};</script> <script type='text/javascript'>__meteor_runtime_config__ = JSON.parse(decodeURIComponent({{meteorRuntimeConfig}}));</script>
{{else}} {{else}}
<script type='text/javascript' src='{{rootUrlPathPrefix}}/meteor_runtime_config.js'></script> <script type='text/javascript' src='{{rootUrlPathPrefix}}/meteor_runtime_config.js'></script>
{{/if}} {{/if}}

View File

@@ -8,7 +8,7 @@
{{#each css}} <link rel="stylesheet" type="text/css" class="__meteor-css__" href="{{../bundledJsCssPrefix}}{{url}}">{{/each}} {{#each css}} <link rel="stylesheet" type="text/css" class="__meteor-css__" href="{{../bundledJsCssPrefix}}{{url}}">{{/each}}
<script type='text/javascript'> <script type='text/javascript'>
__meteor_runtime_config__ = {{meteorRuntimeConfig}}; __meteor_runtime_config__ = JSON.parse(decodeURIComponent({{meteorRuntimeConfig}}));
if (/Android/i.test(navigator.userAgent)) { if (/Android/i.test(navigator.userAgent)) {
// When Android app is emulated, it cannot connect to localhost, // When Android app is emulated, it cannot connect to localhost,

View File

@@ -31,4 +31,5 @@ Package.onUse(function (api) {
Package.onTest(function (api) { Package.onTest(function (api) {
api.use(['tinytest', 'webapp', 'http']); api.use(['tinytest', 'webapp', 'http']);
api.addFiles('webapp_tests.js', 'server'); api.addFiles('webapp_tests.js', 'server');
api.addFiles('webapp_client_tests.js', 'client');
}); });

View File

@@ -0,0 +1,5 @@
// Regression test for #3730
Tinytest.add("webapp - runtime config", function (test) {
test.equal(__meteor_runtime_config__.WEBAPP_TEST_A, '<p>foo</p>');
test.equal(__meteor_runtime_config__.WEBAPP_TEST_B, '</script>');
});

View File

@@ -289,7 +289,14 @@ WebAppInternals.generateBoilerplateInstance = function (arch,
}; };
} }
), ),
meteorRuntimeConfig: JSON.stringify(runtimeConfig), // Convert to a JSON string, then get rid of most weird characters, then
// wrap in double quotes. (The outermost JSON.stringify really ought to
// just be "wrap in double quotes" but we use it to be safe.) This might
// end up inside a <script> tag so we need to be careful to not include
// "</script>", but normal {{spacebars}} escaping escapes too much! See
// https://github.com/meteor/meteor/issues/3730
meteorRuntimeConfig: JSON.stringify(
encodeURIComponent(JSON.stringify(runtimeConfig))),
rootUrlPathPrefix: __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || '', rootUrlPathPrefix: __meteor_runtime_config__.ROOT_URL_PATH_PREFIX || '',
bundledJsCssPrefix: jsCssPrefix, bundledJsCssPrefix: jsCssPrefix,
inlineScriptsAllowed: WebAppInternals.inlineScriptsAllowed(), inlineScriptsAllowed: WebAppInternals.inlineScriptsAllowed(),

View File

@@ -155,3 +155,6 @@ Tinytest.add("webapp - generating boilerplate should not change runtime config",
test.isFalse(__meteor_runtime_config__.WEBAPP_TEST_KEY); test.isFalse(__meteor_runtime_config__.WEBAPP_TEST_KEY);
}); });
__meteor_runtime_config__.WEBAPP_TEST_A = '<p>foo</p>';
__meteor_runtime_config__.WEBAPP_TEST_B = '</script>';

View File

@@ -331,7 +331,8 @@ var generateCordovaBoilerplate = function (projectContext, clientDir, options) {
urlMapper: _.identity, urlMapper: _.identity,
pathMapper: function (p) { return files.pathJoin(clientDir, p); }, pathMapper: function (p) { return files.pathJoin(clientDir, p); },
baseDataExtension: { baseDataExtension: {
meteorRuntimeConfig: JSON.stringify(runtimeConfig) meteorRuntimeConfig: JSON.stringify(
encodeURIComponent(JSON.stringify(runtimeConfig)))
} }
}); });
return boilerplate.toHTML(); return boilerplate.toHTML();