1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/test
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
..
actionpack Merge pull request #15590 from zuhao/refactor_actionview_register_template_handler 2014-06-12 14:06:59 +02:00
activerecord fix bad merge 2014-05-12 18:08:41 -07:00
fixtures Ensure LookupContext in Digestor selects correct variant 2014-03-09 08:47:17 +01:00
lib/controller Moved viewpathstest into actionview/test/actionpack/controller 2013-10-09 20:09:33 +02:00
template Deal with regex match groups in excerpt 2014-06-24 17:01:40 +01:00
tmp Add tmp dir in actionview/test/ 2013-08-05 01:24:14 +05:30
abstract_unit.rb Remove unnecessary include for integration tests. 2014-05-11 16:02:12 -07:00
active_record_unit.rb