From 572d2a8b5aeb51be80ed33926533bf68e7747f9f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 4 Aug 2011 10:18:05 -0400 Subject: [PATCH] ensure bad utf-8 is handled, fixes #48 --- .gitignore | 2 +- lib/jasmine/files_list.rb | 3 +++ spec/lib/jasmine/files_list_spec.rb | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2c8800d..ef518d4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ specrunner.o ext/jasmine-webkit-specrunner/jasmine-webkit-specrunner *.o moc_*.* - +.DS_Store diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index b1313f4..38b414a 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -1,4 +1,5 @@ require 'jasmine-core' +require 'iconv' module Jasmine class FilesList @@ -14,7 +15,9 @@ module Jasmine def get_spec_line_numbers(file) line_numbers = {} + ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') file.lines.each_with_index.each { |line, index| + line = ic.iconv(line + ' ')[0..-2] if description = line[%r{(describe|context|it)[( ]*(["'])(.*)\2}, 3] (line_numbers[description] ||= []) << (index + 1) end diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index 3cd8195..5f3630b 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + require 'spec_helper' require 'jasmine/files_list' require 'fakefs/spec_helpers' @@ -219,6 +221,7 @@ describe 'test', -> context 'yes', -> it 'should do something', -> "yes" + "PR.registerLangHandler(PR.createSimpleLexer([[\"com\",/^#[^\\n\\r]*/,null,\"#\"],[\"pln\",/^[\\t\\n\\r \\xa0]+/,null,\"\\t\\n\\r \xC2\\xa0\"],[\"str\",/^\"(?:[^\"\\\\]|\\\\[\\S\\s])*(?:\"|$)/,null,'\"']],[[\"kwd\",/^(?:ADS|AD|AUG|BZF|BZMF|CAE|CAF|CA|CCS|COM|CS|DAS|DCA|DCOM|DCS|DDOUBL|DIM|DOUBLE|DTCB|DTCF|DV|DXCH|EDRUPT|EXTEND|INCR|INDEX|NDX|INHINT|LXCH|MASK|MSK|MP|MSU|NOOP|OVSK|QXCH|RAND|READ|RELINT|RESUME|RETURN|ROR|RXOR|SQUARE|SU|TCR|TCAA|OVSK|TCF|TC|TS|WAND|WOR|WRITE|XCH|XLQ|XXALQ|ZL|ZQ|ADD|ADZ|SUB|SUZ|MPY|MPR|MPZ|DVP|COM|ABS|CLA|CLZ|LDQ|STO|STQ|ALS|LLS|LRS|TRA|TSQ|TMI|TOV|AXT|TIX|DLY|INP|OUT)\\s/,\n" SPEC end