Browse Source

Escape all non-ascii chars in generated PAC script.

FelisCatus 11 years ago
parent
commit
a008e492b0

+ 2 - 1
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) ->

+ 3 - 1
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

+ 2 - 1
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

+ 6 - 2
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

+ 1 - 0
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")