News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

3.4.0 and 3.2.14 javascript error on category page in backend

Started by stAn99, September 26, 2018, 16:23:55 PM

Previous topic - Next topic

stAn99

javascript error on category page in backend

when using videos or other stuff at the category description.

example of category description that causes the problem (removed customer data):


<p><br /><iframe width="336" height="189" src="https://www.youtube.com/embed/XXXXXXXX?start=6&end=115&rel=0" frameborder="0" allowfullscreen="allowfullscreen" style="float: right;"></iframe></p>
<h2>Car window shades</h2>
<p>Everyone benefits from car window shades, as they are the perfect solution for undesired sunlight. You can buy the best shades at .... We have been developing, producing and selling all kinds of high quality car accessories for over 25 years. At ... we put high value on the use of high quality materials for all our products and a good fit. In addition, we offer our products at very competitive prices.</p>


we fixed the issue with changing code in:
\administrator\components\com_virtuemart\views\category\tmpl\default.php

from

echo shopFunctionsF::limitStringByWord($cat->category_description,200)



to


$desc = strip_tags($cat->category_description);
echo shopFunctionsF::limitStringByWord($desc,200);


i don't think it's necessary to display styled description in category list.

best regards, stan
----
RuposTel.com
www.rupostel.com
Your customized checkout solution for Virtuemart

Jörgen

Nicely caught. Seen this somewhere else in the forum, I think Studio42 reported soemthing similar, i think it was product description.
This
echo shopFunctionsF::limitStringByWord($cat->category_description,200)
breaks for other html tags to not just videos, when You strip the end of other html constructs You get unpredictable errors.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

StefanSTS

I wonder if it is actually unpredictable.

It works very well with most tags. I got lots of category descriptions that work well. They still have the tags, but the content IN the tags is cut. The end tags are still intact. So mostly the limitStringByWord function does it's job.

So if there are cases like that it would be interesting to find out, which tag(s) causes the problem. maybe the function can be adjusted. Someone who is really concerned about it may examine it.

From my point of view the category overview doesn't really need to show the description, it would be just fine to have an option to disable showing the description, which would be nice for the future backend template that seeks to be more usable on mobile devices.

Stefan
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

Jörgen

Yes Ypu can get a lot of descriptions that work well, limitStringByWord does not take any account to html or js syntax it just limits by word, period. If that happens in  the middle of an unclosed tag or js construct the function does not care. This was designed to work with plain text. I do not see why there is any doubt about this?
Using$desc = strip_tags($cat->category_description);
may not solve all the problems but some of the issues, You loose the tags, but it may not break.

The best solution would be is we can close open tags. But that is a bit more complicated.

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

StefanSTS

Quote from: Jörgen on September 26, 2018, 22:59:52 PM
Yes Ypu can get a lot of descriptions that work well, limitStringByWord does not take any account to html or js syntax it just limits by word, period. If that happens in  the middle of an unclosed tag or js construct the function does not care. This was designed to work with plain text. I do not see why there is any doubt about this?

I looked into the function and it actually really just cuts by, not words, but the given number of characters. So it is a limitStringByCharacters, if we are precise.

Breaking the HTML actually always occurs. Just mostly it is not visible in the browser output, because the browsers capability to find errors and correct them will close the open tags automatically.

So where is the problem? The problem starts when the function limitStringByWord cuts inside of an HTML element. In this case we have either an opening "<..." or a closing "</..." and this is what the browser cannot repair by itself.

There is a php snippet on stackoverflow that actually cuts only the text and keeps the HTML tags intact:
https://stackoverflow.com/questions/1193500/truncate-text-containing-html-ignoring-tags

This might be a good idea to adapt. Or just remove the description by default and keep a hidden config to show it.

Stefan
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

stAn99

hello friends, Max just updated the code to use strip_tags within the function which should fix the problem with cutting it at a wrong place.

on the other hand, there will be a hidden config to show the styled category description.

if we wanted to cut it properly, i believe it should go through XML validator before ouputting it which would be way too CPU intensive and not worth implementing it properly.

maybe with the hidden config it could rather show uncut and styled description which should also work OK.

another solution is to use shadow dom with <template> tag but this would again be too much work for something that i don't find useful.

best regards, stan
----
RuposTel.com
www.rupostel.com
Your customized checkout solution for Virtuemart

Studio 42

Quote from: Jörgen on September 26, 2018, 16:52:52 PM
Nicely caught. Seen this somewhere else in the forum, I think Studio42 reported soemthing similar, i think it was product description.
This
echo shopFunctionsF::limitStringByWord($cat->category_description,200)
breaks for other html tags to not just videos, when You strip the end of other html constructs You get unpredictable errors.

Jörgen @ Kreativ Fotografi

Not only this, but filtering on save in database can give strange behavior, UTF-8 not fully supported because mySql bug(i already explained and provided a solution), input broken with double quotes(read forum, solution already given).
Most time my bugs get ignored, so i dont want to fight for nothing, but i can report you other problems i have all months that get not solved as neighbor product in front(solution given for more then 6 months i think) .