franzholz / table

multiple language support for the usage of database tables in TYPO3
0 stars 2 forks source link

transformWhere cuts the clause if quote present #3

Closed webian closed 4 years ago

webian commented 4 years ago

Use case: product articles with quote in size (eg.: 7'11")

With an Input string: article.uid_product=111995 AND (color REGEXP '^[[:blank:]]*(Blue)[[:blank:]]*$' OR color REGEXP '^[[:blank:]]*(Blue)[[:blank:]]*[;]' OR color REGEXP '[;][[:blank:]]*(Blue)[[:blank:]]*$' AND size REGEXP '^[[:blank:]]*(7\'11\")[[:blank:]]*$' OR size REGEXP '^[[:blank:]]*(7\'11\")[[:blank:]]*[;]' OR size REGEXP '[;][[:blank:]]*(7\'11\")[[:blank:]]*$' AND description='' AND gradings='' AND color2='' AND color3='' AND size2='' AND size3='' AND material='' AND quality='') AND article.deleted=0 AND article.hidden=0 AND (article.starttime<=1590307346) AND (article.endtime=0 OR article.endtime>1590307346) AND article.fe_group IN (' ',0,-1)

Method transformWhere returns a cutted clause causing SQL error: article.uid_product=111995 AND (article.color REGEXP '^[[:blank:]]*(Blue) [[:blank:]]*$' OR article.color REGEXP '^[[:blank:]]*(Blue) [[:blank:]]*[;]' OR article.color REGEXP '[;][[:blank:]]*(Blue) [[:blank:]]*$' AND article.size REGEXP '^[[:blank:]]*(7\'11\") [[:blank:]]*$' OR article.size REGEXP '^[[:blank:]]*

franzholz commented 4 years ago

Also the issue #2 must be solved by it. Something is missing. The parts inside of quotes should not be manipulated at all inside of the function.

webian commented 4 years ago

commit https://github.com/franzholz/table/commit/3f0273bccfe813c11d23ce2071d000bd96275989 produces results worse than it was before:

input: article.uid_product=111995 AND (color REGEXP '^[[:blank:]]*(Blue)[[:blank:]]*$' OR color REGEXP '^[[:blank:]]*(Blue)[[:blank:]]*[;]' OR color REGEXP '[;][[:blank:]]*(Blue)[[:blank:]]*$' AND size REGEXP '^[[:blank:]]*(9\'5\")[[:blank:]]*$' OR size REGEXP '^[[:blank:]]*(9\'5\")[[:blank:]]*[;]' OR size REGEXP '[;][[:blank:]]*(9\'5\")[[:blank:]]*$' AND description='' AND gradings='' AND color2='' AND color3='' AND size2='' AND size3='' AND material='' AND quality='') AND article.deleted=0 AND article.hidden=0 AND (article.starttime<=1590481863) AND (article.endtime=0 OR article.endtime>1590481863) AND article.fe_group IN (' ',0,-1)

output after marker replacement: article.uid_product=111995 AND (color REGEXP __QUOTE0__ OR color REGEXP __QUOTE1__ OR color REGEXP __QUOTE2__ AND size REGEXP __QUOTE3__ OR size REGEXP __QUOTE4__ OR size REGEXP __QUOTE5__ AND description=__QUOTE6____QUOTE7____QUOTE8____QUOTE9____QUOTE10____QUOTE11____QUOTE12____QUOTE13__ ',0,-1)

final $result: article.uid_product=111995 AND

(also the commit message of that commit states that it fixes https://github.com/franzholz/table/pull/4 that is a pull request... a commit must fix an issue not a pull request, maybe you mean https://github.com/franzholz/table/issues/3 or https://github.com/franzholz/table/issues/2 or both)

franzholz commented 4 years ago

I cannot reproduce this error. All internal markers are replaced in the result variable before the return.

Your pull request did not fulfill all requirements.

Did you use quotes inside of vairants?

(9\'5\")

This is might not be supported yet. Maybe the searchpattern needs an improvement.

webian commented 4 years ago

Sure I use quotes inside variants. It's all about this issue! It's stated in the first line of my first post in this issue.

franzholz commented 4 years ago

You can check it here. It should take also care of backslashes.

https://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks

Both (use value of capture group #2):

(["'])(.*?[^\\])\1

All support escaped and nested quotes.
franzholz commented 4 years ago

If I use the regular expression checker, then I see that the empty strings are not supported.

https://www.freeformatter.com/regex-tester.html

This part is found and it shouldn't:

 '' AND gradings='' AND color2='' AND color3='' AND size2='' AND size3='' AND material='' AND quality='') AND article.deleted=0 AND article.hidden=0 AND (article.starttime<=1590481863) AND (article.endtime=0 OR article.endtime>1590481863) AND article.fe_group IN ('

Can you find the solution?

webian commented 4 years ago

I'll check and provide a PR...