#333 new
Noah

Difficult to find label containing non-breaking space ( )

Reported by Noah | January 17th, 2010 @ 06:45 PM

Copied from GitHub issue # 30

Created 3 months ago by mislav

I frequently use non-breaking spaces in labels because they should be kept on one line, even if there are multiple words.

<label for="password_confirmation">Repeat&nbsp;password</label>

Of course, this is not a regular space character and, when converted from HTML entity to unicode character, it isn't recognized as space in regular expressions.

As a result, both of these don't work:

fill_in("Repeat password", :with => "test") # /^Repeat password\b/
fill_in("Repeat", :with => "test")          # /^Repeat\b/

A non-breaking space isn't recognized as space or as a word boundary.

A monkeypatch that solves this augments the #all_inner_text method to convert all non-breaking spaces to ordinary space:

class << Webrat::XML
  alias :all_inner_text_with_nbsp :all_inner_text

  # convert non-breaking spaces (&nbsp;) to regular space
  def all_inner_text(element)
    all_inner_text_with_nbsp(element).gsub("\302\240", ' ')
  end
end

This solves the issue globally throughout Webrat.

Comments

martinemde October 19, 2009

It might be a good idea to take a look at where and how all html entities should be handled. I'm sure there's some general rules that would help. For example, should be removed entirely (not sure if this already happens).

mislav October 19, 2009
I agree, but I'd rather call them "characters" instead of "entities", since HTML entities are merely an encoding scheme for special characters in HTML and they get decoded to Unicode (or other) once you start extracting text from web pages using a capable parser like Nokogiri.

Interesting to see that GitHub Flavored Markdown didn't escape ­ in your comment above, but rendered it as-is.

martinemde October 19, 2009
Good point.

Also, very curious about the ­. I sorta breezed right over it assuming it would be escaped. Not sure if I'm escaping it right this time even.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages