<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -22,17 +22,15 @@ module Webrat
     end
     
     def matches_text?(link_text)
-      html = text.gsub('&amp;#xA0;',' ').gsub('&amp;nbsp;', ' ')
-      
       if link_text.is_a?(Regexp)
         matcher = link_text
       else
         matcher = /#{Regexp.escape(link_text.to_s)}/i
       end
-      
-      html =~ matcher || title =~ matcher
+
+      replace_nbsp(text) =~ matcher || replace_nbsp_ref(inner_html) =~ matcher || title =~ matcher
     end
-    
+
     def matches_id?(id_or_regexp)
       if id_or_regexp.is_a?(Regexp)
         (id =~ id_or_regexp) ? true : false
@@ -40,9 +38,13 @@ module Webrat
         (id == id_or_regexp) ? true : false
       end
     end
+
+    def inner_html
+      @element.inner_html
+    end
     
     def text
-      @element.inner_html
+      @element.text
     end
     
   protected
@@ -108,5 +110,13 @@ module Webrat
       end
     end
 
+  private
+    def replace_nbsp(str)
+      str.gsub([0xA0].pack('U'), ' ')
+    end
+
+    def replace_nbsp_ref(str)
+      str.gsub('&amp;#xA0;',' ').gsub('&amp;nbsp;', ' ')
+    end
   end
 end</diff>
      <filename>lib/webrat/core/link.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@ describe Webrat::Link do
 
   before do
     @session = mock(Webrat::TestSession)
+    @link_text_with_nbsp = 'Link' + [0xA0].pack(&quot;U&quot;) + 'Text'
   end
   
   it &quot;should pass through relative urls&quot; do
@@ -22,42 +23,62 @@ describe Webrat::Link do
   
   it &quot;should matches_text? on regexp&quot; do
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Link Text&quot;)
+    link.should_receive(:text).and_return(@link_text_with_nbsp)
     link.matches_text?(/link/i).should == 0
   end
   
   it &quot;should matches_text? on link_text&quot; do
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Link Text&quot;)
+    link.should_receive(:text).and_return(@link_text_with_nbsp)
     link.matches_text?(&quot;Link Text&quot;).should == 0
   end
   
   it &quot;should matches_text? on substring&quot; do
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Link Text&quot;)
+    link.should_receive(:text).and_return(@link_text_with_nbsp)
     link.matches_text?(&quot;nk Te&quot;).should_not be_nil
   end
   
   it &quot;should not matches_text? on link_text case insensitive&quot; do
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Link Text&quot;)
+    link.should_receive(:text).and_return(@link_text_with_nbsp)
+    link.should_receive(:inner_html).and_return('Link&amp;nbsp;Text')
     link.should_receive(:title).and_return(nil)
     link.matches_text?(&quot;link_text&quot;).should == false
   end
   
-  it &quot;should match text including &amp;nbsp;&quot; do
+  it &quot;should match text not include &amp;nbsp;&quot; do
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Link&amp;nbsp;Text&quot;)
-    link.matches_text?(&quot;Link Text&quot;).should == 0
+    link.should_receive(:text).and_return('LinkText')
+    link.matches_text?(&quot;LinkText&quot;).should == 0
   end
   
   it &quot;should not matches_text? on wrong text&quot; do 
     link = Webrat::Link.new(@session, nil)
-    link.should_receive(:text).and_return(&quot;Some Other Link&quot;)
+    nbsp = [0xA0].pack(&quot;U&quot;)
+    link.should_receive(:text).and_return(&quot;Some&quot;+nbsp+&quot;Other&quot;+nbsp+&quot;Link&quot;)
+    link.should_receive(:inner_html).and_return(&quot;Some&amp;nbsp;Other&amp;nbsp;Link&quot;)
     link.should_receive(:title).and_return(nil)
     link.matches_text?(&quot;Link Text&quot;).should == false
   end
-  
+
+  it &quot;should match text including character reference&quot; do
+    no_ko_gi_ri = [0x30CE,0x30B3,0x30AE,0x30EA]
+    nokogiri_ja_kana = no_ko_gi_ri.pack(&quot;U*&quot;)
+    nokogiri_char_ref = no_ko_gi_ri.map{|c| &quot;&amp;#x%X;&quot; % c }.join(&quot;&quot;)
+
+    link = Webrat::Link.new(@session, nil)
+    link.should_receive(:text).and_return(nokogiri_ja_kana)
+    link.matches_text?(nokogiri_ja_kana).should == 0
+  end
+
+  it &quot;should match img link&quot; do
+    link = Webrat::Link.new(@session, nil)
+    link.should_receive(:text).and_return('')
+    link.should_receive(:inner_html).and_return('&lt;img src=&quot;logo.png&quot; /&gt;')
+    link.matches_text?('logo.png').should == 10
+  end
+
   it &quot;should matches_id? on exact matching id&quot; do
     link = Webrat::Link.new(@session, nil)
     link.should_receive(:id).and_return(&quot;some_id&quot;)
@@ -76,4 +97,4 @@ describe Webrat::Link do
     link.matches_id?(/some/).should == true
   end
   
-end
\ No newline at end of file
+end</diff>
      <filename>spec/webrat/core/link_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>95604d6320fc145584081042b698e07635ae7cb4</id>
    </parent>
  </parents>
  <author>
    <name>moro</name>
    <email>moronatural@gmail.com</email>
  </author>
  <url>http://github.com/brynary/webrat/commit/dc52f07a9f9b8debfd1562c9c119154dd8856e27</url>
  <id>dc52f07a9f9b8debfd1562c9c119154dd8856e27</id>
  <committed-date>2008-11-18T17:37:35-08:00</committed-date>
  <authored-date>2008-11-17T17:43:43-08:00</authored-date>
  <message>Link#matches_text?() use @element.text as text

It decodes character references.
Userful for multibyte languages(eg. Japanese).

And also uses @element.inner_html to match with HTML (eg.image link)</message>
  <tree>35cfeb6ca36de98af0a530d788a7aa3abadc617b</tree>
  <committer>
    <name>Bryan Helmkamp</name>
    <email>bryan@brynary.com</email>
  </committer>
</commit>
