Escape all non-ascii chars in generated PAC script.

This commit is contained in:
FelisCatus 2014-09-24 11:33:09 +08:00
parent 4c65b47860
commit a008e492b0
5 changed files with 14 additions and 5 deletions

View File

@ -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) ->

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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")