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

Truncate is cutting within a tag #11934

Closed
laoneo opened this issue Sep 5, 2016 · 14 comments
Closed

Truncate is cutting within a tag #11934

laoneo opened this issue Sep 5, 2016 · 14 comments

Comments

@laoneo
Copy link
Member

laoneo commented Sep 5, 2016

Truncating a string is not working 100% when attributes are set. The following code is producing incorrect HTML output Some text is <div..., even the doc comment says it closes open tags.

JHtml::_('string.truncate', 'Some text is <div class="test"><span><i>Plain</i></span></div>', 16);

Probably the whole function needs to be rewritten, using a DOM parser.

Steps to reproduce the issue

In the file tests/unit/suites/libraries/cms/html/JHtmlStringTest.php after line 210, add the following code

'Dont show open tags' => array(
                'Some text is <div class="test"><span><i>Plain</i></span></div>',
                20,
                true,
                true,
                'Some text is ',
            ),

Run phpunit tests/unit/suites/libraries/cms/html/JHtmlStringTest.php.

Expected result

Unit test will run trough.

Actual result

1) JHtmlStringTest::testTruncate with data set "HTML not allowed, no split" ('Some text is <div class="test...</div>', 20, true, true, 'Some text is ')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Some text is '
+'Some text is <div...'

System information (as much as possible)

Joomla 3.6.2 on PHP 7.

@rdeutz
Copy link
Contributor

rdeutz commented Sep 6, 2016

I have made a fix for this years ago but nobody gave a fu?? and chose to discuss it to dead. Will check if I can find the fix. The problem is the space within the tag, if that is the place to spilt then anything goes south.

@laoneo
Copy link
Member Author

laoneo commented Sep 6, 2016

Hope you will find the fix again 😬

@brianteeman
Copy link
Contributor

Do you mean #978

On 6 September 2016 at 13:47, Robert Deutz notifications@github.com wrote:

I have made a fix for this years ago but nobody gave a fu?? and chose to
discuss it to dead. Will check if I can find the fix. The problem is the
space within the tag, if that is the place to spilt then anything goes
south.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#11934 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPH8RQuIBobUR9k5OWHrvHUDM43MyrGks5qnWDlgaJpZM4J05V3
.

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

@brianteeman
Copy link
Contributor

or this one #1665

On 6 September 2016 at 13:52, Brian Teeman brian@teeman.net wrote:

Do you mean #978

On 6 September 2016 at 13:47, Robert Deutz notifications@github.com
wrote:

I have made a fix for this years ago but nobody gave a fu?? and chose to
discuss it to dead. Will check if I can find the fix. The problem is the
space within the tag, if that is the place to spilt then anything goes
south.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#11934 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPH8RQuIBobUR9k5OWHrvHUDM43MyrGks5qnWDlgaJpZM4J05V3
.

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

@rdeutz
Copy link
Contributor

rdeutz commented Sep 6, 2016

The "endless" story is here on joomlacode 30552 :-) and yes #1665 seems to be the last one. It only happens from time to time more then 3 years someone faced the same problem. Going to make a patch soon

@laoneo
Copy link
Member Author

laoneo commented Sep 6, 2016

@rdeutz thank you!
@brianteeman did you remember the ids without search 😄 ?

@rdeutz
Copy link
Contributor

rdeutz commented Sep 6, 2016

Tried it, but old patch doesn't work, I need a bit more time to check and fix

@brianteeman
Copy link
Contributor

@brianteeman did you remember the ids without search 😄 ?

of course

@eshiol
Copy link
Contributor

eshiol commented Oct 30, 2016

JHtmlString::truncateComplex solved the issue #12612 because it is more reliable than JHtmlString::truncate. What do you think to change JHtmlString::truncate so you automatically use JHtmlString::truncateComplex when allowHtml is true?

@laoneo
Copy link
Member Author

laoneo commented Nov 1, 2016

JHtmlString::truncateComplex is also not solving the issue as the error happens there as well.

@ghost
Copy link

ghost commented Jan 31, 2017

is this Issue similar to #11835, #13594?

@laoneo
Copy link
Member Author

laoneo commented Feb 11, 2017

@franz-wohlkoenig no. This one here is about real truncating HTML code by removing letters and keeping the HTML structure valid like closing opening tags after truncate.

@ghost
Copy link

ghost commented Feb 11, 2017

thanks for info, @laoneo

@rdeutz
Copy link
Contributor

rdeutz commented Mar 26, 2017

closing because we have a PR #14907

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