?
avatar laoneo
laoneo
5 Sep 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.

avatar laoneo laoneo - open - 5 Sep 2016
avatar laoneo laoneo - change - 5 Sep 2016
The description was changed
avatar laoneo laoneo - edited - 5 Sep 2016
avatar brianteeman brianteeman - change - 5 Sep 2016
Labels Added: ?
avatar rdeutz
rdeutz - comment - 6 Sep 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.

avatar laoneo
laoneo - comment - 6 Sep 2016

Hope you will find the fix again ?

avatar brianteeman
brianteeman - comment - 6 Sep 2016

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/

avatar brianteeman
brianteeman - comment - 6 Sep 2016

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/

avatar rdeutz
rdeutz - comment - 6 Sep 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

avatar laoneo
laoneo - comment - 6 Sep 2016

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

avatar rdeutz
rdeutz - comment - 6 Sep 2016

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

avatar brianteeman
brianteeman - comment - 6 Sep 2016

@brianteeman did you remember the ids without search ? ?

of course

avatar brianteeman brianteeman - change - 2 Oct 2016
Category Libraries
avatar eshiol
eshiol - comment - 30 Oct 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?

avatar laoneo
laoneo - comment - 1 Nov 2016

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

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 31 Jan 2017

is this Issue similar to #11835, #13594?

avatar laoneo
laoneo - comment - 11 Feb 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.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 11 Feb 2017

thanks for info, @laoneo

avatar rdeutz
rdeutz - comment - 26 Mar 2017

closing because we have a PR #14907

avatar rdeutz rdeutz - change - 26 Mar 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-03-26 14:37:07
Closed_By rdeutz
avatar rdeutz rdeutz - close - 26 Mar 2017

Add a Comment

Login with GitHub to post a comment