Author Topic: 3.4.0 and 3.2.14 javascript error on category page in backend  (Read 644 times)

stAn99

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 81
    • One Page Checkout for Virtuemart 2
3.4.0 and 3.2.14 javascript error on category page in backend
« on: September 26, 2018, 16:23:55 pm »
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):

Code: [Select]
<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
Code: [Select]
echo shopFunctionsF::limitStringByWord($cat->category_description,200)


to

Code: [Select]
$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

  • Global Moderator
  • Full Member
  • *
  • Posts: 2235
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #1 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
Code: [Select]
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.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

StefanSTS

  • Global Moderator
  • Jr. Member
  • *
  • Posts: 332
  • VirtueMart Version: VM 4.2 on Joomla 4.5
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #2 on: September 26, 2018, 17:23:36 pm »
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

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2235
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #3 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?
Using
Code: [Select]
$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.8
Virtuemart 3.4.x
Olympiantheme Hera (customized)

StefanSTS

  • Global Moderator
  • Jr. Member
  • *
  • Posts: 332
  • VirtueMart Version: VM 4.2 on Joomla 4.5
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #4 on: September 27, 2018, 10:54:12 am »
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

stAn99

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 81
    • One Page Checkout for Virtuemart 2
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #5 on: September 27, 2018, 11:01:35 am »
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3905
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
Re: 3.4.0 and 3.2.14 javascript error on category page in backend
« Reply #6 on: September 27, 2018, 11:18:35 am »
Nicely caught. Seen this somewhere else in the forum, I think Studio42 reported soemthing similar, i think it was product description.
This
Code: [Select]
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) .