Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Fix a bug in obfuscating unicode strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
joevennix committed Oct 22, 2015
1 parent f76a052 commit e363006
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/jsobfu/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def self.string_to_bytes(str)
str.slice!(0, $1.length)
end
else
char = str.slice!(0,1).unpack("C").first
char = str.slice!(0,1).unpack("U").first
end
encoded_bytes << rand_base(char) if char
end
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/unicode_strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function unicodeString() {
return '你好';
}

this.test = function() {
var unicode = unicodeString();
if (unicode !== '你好') throw 'UNICODE CHARS DO NOT MATCH: '+unicode;
return 'unicode chars match'
};
5 changes: 5 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
unless ENV['INTEGRATION'] == 'false'

describe 'Integrations' do
match = ENV['MATCH']
Dir.glob(Pathname.new(__FILE__).dirname.join('integration/**.js').to_s).each do |path|
if match and !path.downcase.include?(match.downcase)
next
end

js = File.read(path)

if js =~ /\/\/@wip/
Expand Down
4 changes: 2 additions & 2 deletions spec/jsobfu/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def output; JSObfu::Utils.rand_text_alphanumeric(len); end

describe '#rand_text_alpha' do
let(:len) { 15 }

# generates a new random string on every call
def output; JSObfu::Utils.rand_text_alpha(len); end

Expand All @@ -34,7 +34,7 @@ def output; JSObfu::Utils.rand_text_alpha(len); end
end
end

describe '#rand_text' do
describe '#rand_text' do
let(:len) { 5 }
let(:charset) { described_class::ALPHA_CHARSET }

Expand Down

0 comments on commit e363006

Please sign in to comment.