From a008e492b03adf6d34e8715a89532fd7a0d6effd Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Wed, 24 Sep 2014 11:33:09 +0800 Subject: [PATCH] Escape all non-ascii chars in generated PAC script. --- omega-pac/src/pac_generator.coffee | 3 ++- omega-target-chromium-extension/src/chrome_api.coffee | 4 +++- omega-target-chromium-extension/src/options.coffee | 3 ++- omega-target/src/options.coffee | 8 ++++++-- omega-web/src/omega/controllers/master.coffee | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/omega-pac/src/pac_generator.coffee b/omega-pac/src/pac_generator.coffee index d38eade..78166f2 100644 --- a/omega-pac/src/pac_generator.coffee +++ b/omega-pac/src/pac_generator.coffee @@ -8,7 +8,8 @@ module.exports = str.replace /[\u0080-\uffff]/g, (char) -> hex = char.charCodeAt(0).toString(16) result = '\\u' - result += '0' for _ in [hex.length..4] + result += '0' for _ in [hex.length...4] + result += hex return result compress: (ast) -> diff --git a/omega-target-chromium-extension/src/chrome_api.coffee b/omega-target-chromium-extension/src/chrome_api.coffee index 6977bca..9fe35f5 100644 --- a/omega-target-chromium-extension/src/chrome_api.coffee +++ b/omega-target-chromium-extension/src/chrome_api.coffee @@ -6,7 +6,9 @@ chromeApiPromisifer = (originalMethod) -> new Promise (resolve, reject) => callback = (callbackArgs...) -> if chrome.runtime.lastError? - return reject(chrome.runtime.lastError) + error = new Error(chrome.runtime.lastError.message) + error.original = chrome.runtime.lastError + return reject(error) if callbackArgs.length <= 1 resolve(callbackArgs[0]) else diff --git a/omega-target-chromium-extension/src/options.coffee b/omega-target-chromium-extension/src/options.coffee index 43c6cc9..f0e5dc1 100644 --- a/omega-target-chromium-extension/src/options.coffee +++ b/omega-target-chromium-extension/src/options.coffee @@ -135,7 +135,8 @@ class ChromeOptions extends OmegaTarget.Options data: null mandatory: true setPacScript = @pacForProfile(profile).then (script) -> - profileName = JSON.stringify(profile.name).replace(/\*/g, '\\u002a') + profileName = OmegaPac.PacGenerator.ascii(JSON.stringify(profile.name)) + profileName = profileName.replace(/\*/g, '\\u002a') profileName = profileName.replace(/\\/g, '\\u002f') prefix = "/*OmegaProfile*#{profileName}*#{profile.revision}*/" config['pacScript'].data = prefix + script diff --git a/omega-target/src/options.coffee b/omega-target/src/options.coffee index dd0c6a4..e65b205 100644 --- a/omega-target/src/options.coffee +++ b/omega-target/src/options.coffee @@ -71,8 +71,12 @@ class Options @applyProfile('system') else @applyProfile(st['currentProfileName'] || @fallbackProfileName) - ).catch(ProfileNotExistError, => + ).catch((err) => + if not err instanceof ProfileNotExistError + @log.error(err) @applyProfile(@fallbackProfileName) + ).catch((err) => + @log.error(err) ).then => @getAll() @ready.then => @@ -269,7 +273,7 @@ class Options ast = OmegaPac.PacGenerator.script(@_options, profile) if compress ast = OmegaPac.PacGenerator.compress(ast) - Promise.resolve ast.print_to_string() + Promise.resolve OmegaPac.PacGenerator.ascii(ast.print_to_string()) _setAvailableProfiles: -> profile = if @_currentProfileName then @currentProfile() else null diff --git a/omega-web/src/omega/controllers/master.coffee b/omega-web/src/omega/controllers/master.coffee index c442ba5..ab48daa 100644 --- a/omega-web/src/omega/controllers/master.coffee +++ b/omega-web/src/omega/controllers/master.coffee @@ -42,6 +42,7 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window, return if profile.profileType in ['DirectProfile', 'SystemProfile'] ast = OmegaPac.PacGenerator.script($rootScope.options, profileName) pac = ast.print_to_string(beautify: true, comments: true) + pac = OmegaPac.PacGenerator.ascii(pac) blob = new Blob [pac], {type: "text/plain;charset=utf-8"} fileName = profileName.replace(/\W+/g, '_') saveAs(blob, "OmegaProfile_#{fileName}.pac")