Skip to content

Commit

Permalink
Added that UrlHelper#mail_to will now also encode the default link ti…
Browse files Browse the repository at this point in the history
…tle #749 [f.svehla@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1601 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jul 2, 2005
1 parent 3553b59 commit a53372c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* Added that UrlHelper#mail_to will now also encode the default link title #749 [f.svehla@gmail.com]

* Removed the default option of wrap=virtual on FormHelper#text_area to ensure XHTML compatibility #1300 [thomas@columbus.rr.com] * Removed the default option of wrap=virtual on FormHelper#text_area to ensure XHTML compatibility #1300 [thomas@columbus.rr.com]


* Adds the ability to include XML CDATA tags using Builder #1563 [Josh Knowles]. Example: * Adds the ability to include XML CDATA tags using Builder #1563 [Josh Knowles]. Example:
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/active_record_helper.rb
Expand Up @@ -31,7 +31,7 @@ def input(record_name, method)
# </p> # </p>
# <p> # <p>
# <label for="post_body">Body</label><br /> # <label for="post_body">Body</label><br />
# <textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual"> # <textarea cols="40" id="post_body" name="post[body]" rows="20">
# Back to the hill and over it again! # Back to the hill and over it again!
# </textarea> # </textarea>
# </p> # </p>
Expand Down
8 changes: 6 additions & 2 deletions actionpack/lib/action_view/helpers/url_helper.rb
Expand Up @@ -187,6 +187,10 @@ def mail_to(email_address, name = nil, html_options = {})
extras << "subject=#{CGI.escape(subject).gsub("+", "%20")}&" unless subject.nil? extras << "subject=#{CGI.escape(subject).gsub("+", "%20")}&" unless subject.nil?
extras = "?" << extras.gsub!(/&?$/,"") unless extras.empty? extras = "?" << extras.gsub!(/&?$/,"") unless extras.empty?


email_address_obfuscated = email_address.dup
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.has_key?("replace_at")
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.has_key?("replace_dot")

if encode == 'javascript' if encode == 'javascript'
tmp = "document.write('#{content_tag("a", name || email_address, html_options.merge({ "href" => "mailto:"+email_address.to_s+extras }))}');" tmp = "document.write('#{content_tag("a", name || email_address, html_options.merge({ "href" => "mailto:"+email_address.to_s+extras }))}');"
for i in 0...tmp.length for i in 0...tmp.length
Expand All @@ -201,9 +205,9 @@ def mail_to(email_address, name = nil, html_options = {})
string << email_address[i,1] string << email_address[i,1]
end end
end end
content_tag "a", name || email_address, html_options.merge({ "href" => "mailto:#{string}#{extras}" }) content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{string}#{extras}" })
else else
content_tag "a", name || email_address, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" }) content_tag "a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:#{email_address}#{extras}" })
end end
end end


Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/template/active_record_helper_test.rb
Expand Up @@ -65,7 +65,7 @@ def test_generic_input_tag


def test_text_area_with_errors def test_text_area_with_errors
assert_equal( assert_equal(
%(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea></div>), %(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
text_area("post", "body") text_area("post", "body")
) )
end end
Expand All @@ -79,7 +79,7 @@ def test_text_field_with_errors


def test_form_with_string def test_form_with_string
assert_equal( assert_equal(
%(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>), %(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
form("post") form("post")
) )


Expand All @@ -89,7 +89,7 @@ def to_param() id end
def id() 1 end def id() 1 end
end end
assert_equal( assert_equal(
%(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>), %(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
form("post") form("post")
) )
end end
Expand Down
12 changes: 6 additions & 6 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -100,22 +100,22 @@ def test_radio_button


def test_text_area def test_text_area
assert_equal( assert_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>', '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
text_area("post", "body") text_area("post", "body")
) )
end end


def test_text_area_with_escapes def test_text_area_with_escapes
@post.body = "Back to <i>the</i> hill and over it again!" @post.body = "Back to <i>the</i> hill and over it again!"
assert_equal( assert_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to &lt;i&gt;the&lt;/i&gt; hill and over it again!</textarea>', '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to &lt;i&gt;the&lt;/i&gt; hill and over it again!</textarea>',
text_area("post", "body") text_area("post", "body")
) )
end end


def test_date_selects def test_date_selects
assert_equal( assert_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>', '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
text_area("post", "body") text_area("post", "body")
) )
end end
Expand All @@ -125,7 +125,7 @@ def test_explicit_name
'<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess") '<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
) )
assert_equal( assert_equal(
'<textarea cols="40" id="post_body" name="really!" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>', '<textarea cols="40" id="post_body" name="really!" rows="20">Back to the hill and over it again!</textarea>',
text_area("post", "body", "name" => "really!") text_area("post", "body", "name" => "really!")
) )
assert_equal( assert_equal(
Expand All @@ -145,7 +145,7 @@ def test_explicit_id
'<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess") '<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess")
) )
assert_equal( assert_equal(
'<textarea cols="40" id="really!" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>', '<textarea cols="40" id="really!" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
text_area("post", "body", "id" => "really!") text_area("post", "body", "id" => "really!")
) )
assert_equal( assert_equal(
Expand All @@ -166,7 +166,7 @@ def test_auto_index
"<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />", text_field("post[]","title") "<input id=\"post_#{pid}_title\" name=\"post[#{pid}][title]\" size=\"30\" type=\"text\" value=\"Hello World\" />", text_field("post[]","title")
) )
assert_equal( assert_equal(
"<textarea cols=\"40\" id=\"post_#{pid}_body\" name=\"post[#{pid}][body]\" rows=\"20\" wrap=\"virtual\">Back to the hill and over it again!</textarea>", "<textarea cols=\"40\" id=\"post_#{pid}_body\" name=\"post[#{pid}][body]\" rows=\"20\">Back to the hill and over it again!</textarea>",
text_area("post[]", "body") text_area("post[]", "body")
) )
assert_equal( assert_equal(
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Expand Up @@ -116,6 +116,14 @@ def test_mail_to_with_hex
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex") assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
end end


def test_mail_to_with_replace_options
assert_equal "<a href=\"mailto:wolfgang@stufenlos.net\">wolfgang(at)stufenlos(dot)net</a>", mail_to("wolfgang@stufenlos.net", nil, :replace_at => "(at)", :replace_dot => "(dot)")
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain.com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)")
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)")
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain(dot)com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)")
assert_equal "<script type=\"text/javascript\" language=\"javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
end

def test_link_with_nil_html_options def test_link_with_nil_html_options
assert_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil) assert_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil)
end end
Expand Down

0 comments on commit a53372c

Please sign in to comment.