Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanitizer truncate - some parameter are ignored #1015

Closed
Klenkes opened this issue Oct 30, 2019 · 5 comments
Closed

sanitizer truncate - some parameter are ignored #1015

Klenkes opened this issue Oct 30, 2019 · 5 comments

Comments

@Klenkes
Copy link

Klenkes commented Oct 30, 2019

Short description of the issue

Using $sanitizer->truncate like this:
wire('sanitizer')->truncate($item->body, $maxLength=200);
wire('sanitizer')->truncate($item->body, 200, array('underlineHeadlines' => false));

Expected behavior

In PW 3.0.123 the result was pure text with no HTML tags and no linebreaks, ready to be used for example in a search results page

Actual behavior

underlineHeadlines is used(true), so that every headline is followed by ===(h2) or ---(h3)
It used to work correctly in PW 3.0.123 but not anymore in 3.0.143
truncated-text

Related forum post with more description and screenshots(by me)

https://processwire.com/talk/topic/22491-sanitizer-truncate-inserts-as-breaks/
older post:
https://processwire.com/talk/topic/22190-truncate-leads-to-crazy-link-leftovers/
Could be on to the source of the problem:
https://processwire.com/talk/topic/22491-sanitizer-truncate-inserts-as-breaks/?do=findComment&comment=192949

Versions

PW 3.0.123 = okay
PW 3.0.143 = not okay
PHP 5.6 up to 7.2

@adrianbj
Copy link

I came across this recently as well. As a workaround, this works:

$sanitizer->truncate($sanitizer->textarea(

@Klenkes
Copy link
Author

Klenkes commented Oct 30, 2019

True, but there are still some residual ellipses for each heading that has been removed. This can't be right.
truncated-text-3
And since I am in my _func.php I have to use:
wire('sanitizer')->truncate( wire('sanitizer')->textarea($item->body, array('maxLength' => 200)) ) . '...';

ryancramerdesign added a commit to processwire/processwire that referenced this issue Nov 5, 2019
@ryancramerdesign
Copy link
Member

Thanks @Klenkes I've pushed a fix for this issue, though the issue is not that "some parameter ignored" because 'underlineHeadlines' is not a documented option/param for the truncate() method. The problem was instead that it wasn't properly applying (by disabling) that option when having the markupToText() strip markup. I have updated it so that it is now properly disabling options that shouldn't appear in truncate/collapse calls.

Regarding the ellipsis appearing between headlines or headline + other text: that is the correct behavior. It can however be adjusted with the 'collapseLinesWith' option. Though that's an option I would not recommend disabling unless you have some other kind of punctuation accommodating it. Otherwise it can result in creating sentences that aren't meant to be merged, creating unusual, awkward, gibberish or humorous combinations that appear as full sentences but aren't in the source markup.

@Klenkes
Copy link
Author

Klenkes commented Nov 6, 2019

Regarding the ellipsis appearing between headlines
You are right. Switching this off could be unintentionally funny...

@Klenkes
Copy link
Author

Klenkes commented Nov 11, 2019

Seems to work fine now.

@Klenkes Klenkes closed this as completed Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants