1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

18 commits

Author SHA1 Message Date
Ben Woodall
7b4c6dca43 Fixes simple missprint in docs for #cyle in text_helper 2014-12-30 12:09:47 -08:00
igor04
0e50b7bdf4 Added processing of nil to highlight helper method 2014-09-30 14:48:48 +03:00
Gareth Rees
124f88eaa2 Deal with regex match groups in excerpt
Original implementation has bugs if the regex contains a match group.

Example:

    excerpt('This is a beautiful? morning', /\b(beau\w*)\b/i, :radius => 5)
    Expected: "...is a beautiful? mor..."
    Actual: "...is a beautifulbeaut..."

The original phrase was being converted to a regex and returning the text
either side of the phrase as expected:

    'This is a beautiful? morning'.split(/beautiful/i, 2)
    # => ["This is a ", "? morning"]

When we have a match with groups the match is returned in the array.

Quoting the ruby docs: "If pattern is a Regexp, str is divided where the
pattern matches. [...] If pattern contains groups, the respective matches will
be returned in the array as well."

    'This is a beautiful? morning'.split(/\b(beau\w*)\b/iu, 2)
    # => ["This is a ", "beautiful", "? morning"]

If we assume we want to split on the first match – this fix makes that
assumption – we can pass the already assigned `phrase` variable as the place
to split (because we already know that a match exists from line 168).

Originally spotted by Louise Crow (@crowbot) at
https://github.com/mysociety/alaveteli/pull/1557
2014-06-24 17:01:40 +01:00
Lucas Mazza
9f27e1076a 'TextHelper#highlight' now accepts a block to highlight the matched words.
The helper will yield each matched word, and you can use this instead of the
':highlighter' option for more complex replacing logic:

  highlight('My email is me@work.com', EMAIL_REGEXP) { |m| mail_to(m) }
  # => 'My email is <a href="mailto:me@work.com">me@work.com</a>'
2014-06-19 15:22:23 -03:00
Jan Szumiec
490f25034d highlight() now accepts regular expressions as well. 2014-06-19 14:53:18 -03:00
Jan Szumiec
2b617783ad excerpt() now accepts regular expression instances as phrases. 2014-06-19 14:44:59 -03:00
Konstantin Wlasow
9882ec4a50 Fixed documentation. [ci skip] 2014-01-04 16:18:16 +06:00
Rafael Mendonça França
a220b1518d Merge pull request #13059 from imkmf/cycle-accepts-array
Cycle object should accept an array

Conflicts:
	actionview/CHANGELOG.md
2013-12-06 17:05:59 -02:00
Kristian Freeman
1eaa521273 A Cycle object should accept an array and cycle through it as it would
with a set of comma-separated objects.
2013-12-06 10:57:37 -08:00
Mario Visic
a156562762 Fix issue where TextHelper#simple_format was calling missing 'raw' method 2013-12-05 00:21:55 +11:00
Rafael Mendonça França
da633f81eb Remove the escaping skip
We are generating safe strings in the paragraph, so we can escape the
tags
2013-12-03 17:26:49 -02:00
Michael Koziarski
bea9c9b4c0 Ensure simple_format escapes its html attributes
The previous behavior equated the sanitize option for simple_format with the
escape option of content_tag, however these are two distinct concepts.

This fixes CVE-2013-6416

Conflicts:
	actionview/lib/action_view/helpers/text_helper.rb
2013-12-02 16:42:07 -08:00
pseidemann
881a2cc907 fix simple_format escapes own output when sanitize is set to true 2013-11-08 17:13:59 +01:00
Paul Nikitochkin
061e48df26 Cleanup of excerpt helper
* replaced String concatenation by joining
* separator has default value to '', even it is nil
2013-09-06 18:00:55 +03:00
Jan Szumiec
512603ee32 Removed an unnecessary loop - it kills performance on large texts. 2013-08-03 23:56:38 +01:00
Vipul A M
4ce11c0150 Change from map => map! and collect! to save creation of extra array. 2013-07-31 10:07:04 +05:30
Matt Bridges
7e1cb39f72 Fix simple_format output example ending tag 2013-07-09 14:09:26 -05:00
Piotr Sarnacki
0d6e8edc2a Move actionpack/lib/action_view* into actionview/lib 2013-06-20 17:23:15 +02:00
Renamed from actionpack/lib/action_view/helpers/text_helper.rb (Browse further)