Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

I fixed bug for Chinese content. #2

Merged
merged 2 commits into from

2 participants

@huacnlee

I am add a test in the spec.

@myobie myobie merged commit c3b9112 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +5 −2 lib/htmldiff.rb
  2. +7 −1 spec/htmldiff_spec.rb
View
7 lib/htmldiff.rb
@@ -240,7 +240,7 @@ def wrap_text(text, tagname, cssclass)
end
def explode(sequence)
- sequence.is_a?(String) ? sequence.split(//) : sequence
+ sequence.is_a?(String) ? sequence.split("") : sequence
end
def end_of_tag?(char)
@@ -284,8 +284,11 @@ def convert_html_to_list_of_words(x, use_brackets = false)
words << current_word unless current_word.empty?
current_word = char
mode = :whitespace
- else
+ elsif /[\w\#@]+/i.match char
current_word << char
+ else
+ words << current_word unless current_word.empty?
+ current_word = char
end
when :whitespace
if start_of_tag? char
View
8 spec/htmldiff_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
require 'htmldiff'
@@ -28,5 +29,10 @@ class TestDiff
diff = TestDiff.diff('a b c', 'a d c')
diff.should == "a <del class=\"diffmod\">b</del><ins class=\"diffmod\">d</ins> c"
end
+
+ it "should support Chinese" do
+ diff = TestDiff.diff('这个是中文内容, Ruby is the bast', '这是中国语内容,Ruby is the best language.')
+ diff.should == "这<del class=\"diffdel\">个</del>是中<del class=\"diffmod\">文</del><ins class=\"diffmod\">国语</ins>内<del class=\"diffmod\">容, Ruby</del><ins class=\"diffmod\">容,Ruby</ins> is the <del class=\"diffmod\">bast</del><ins class=\"diffmod\">best language.</ins>"
+ end
-end
+end
Something went wrong with that request. Please try again.