Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11268 (closed defect: fixed)

Opened 2 months ago

Last modified 2 months ago

[PATCH] TextHelper::excerpt excerpts 1 character too many after the matching phrase

Reported by: Irfy Assigned to: core
Priority: low Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: TextHelper excerpt
Cc:

Description

Analyzed according to its documentation, TextHelper::excerpt excerpts 1 character too many after the matching phrase in the text. A side effect of this is for example:

>> excerpt 'ab', 'a', 0
=> "ab..."

Documentation provides examples consistent with this behavior, contradicting the description of the function itself. Tests are consistent with this behavior too, but contradict the description in the same way.

Provided is a patch that

  • fixes the documentation,
  • fixes the function itself
  • fixes the existing tests
  • adds another test to test behavior in borderline cases (such as the example above).

Additionally, the text "The resulting string will be stripped in any case." is added to the documentation to document this peculiar behavior, for example:

>> excerpt(" zabcd ", "b", 3)
=> "zabcd"

Whether this behavior is meaningful or desired can be discussed, but I thought it should at least be documented. (In my opinion the string should only be lstripped or rstripped if the real excerpt_string is being prepended or appended, respectively)

I ran the tests with Ruby 1.8.6, if someone with 1.9 could test this, I'd be thankful (I modified the 1.9 version of excerpt and tests blindly).

Attachments

corrected_text_helper_excerpt_and_tests.diff (6.1 kB) - added by Irfy on 03/03/08 03:11:31.

Change History

03/03/08 03:11:31 changed by Irfy

  • attachment corrected_text_helper_excerpt_and_tests.diff added.

03/03/08 03:14:11 changed by Irfy

  • summary changed from TextHelper::excerpt excerpts 1 character too many after the matching phrase to [PATCH] TextHelper::excerpt excerpts 1 character too many after the matching phrase.

03/15/08 19:59:38 changed by david

  • status changed from new to closed.
  • resolution set to fixed.

(In [9030]) Fixed that TextHelper#excerpt would include one character too many (closes #11268) [Irfy]