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

Fatal error related to strpos usage #57

Open
Mark-H opened this issue Feb 16, 2023 · 1 comment
Open

Fatal error related to strpos usage #57

Mark-H opened this issue Feb 16, 2023 · 1 comment

Comments

@Mark-H
Copy link

Mark-H commented Feb 16, 2023

Found this on a client MODX 2.8.4 / PHP 8.0 / SimpleSearch 2.1.2 site's php error log going back many months:

PHP Fatal error:  Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in /www/core/components/simplesearch/model/simplesearch/simplesearch.class.php:437
Stack trace:
#0 /www/core/components/simplesearch/model/simplesearch/simplesearch.class.php(437): strpos()
#1 /www/core/cache/includes/elements/modsnippet/2.include.cache.php(91): SimpleSearch->createExtract()
#2 /www/core/model/modx/modscript.class.php(76): include('...')
#3 /www/core/model/modx/modparser.class.php(537): modScript->process()
#4 /www/core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag()
#5 /www/core/model/modx/modparser.class.php(251): pdoParser->processTag()
#6 /www/core/components/pdotools/model/pdotools/pdoparser.class.php(64): modParser->processElementTags()
#7 /www/core/model/modx/modresource.class.php(546): pdoParser->processElementTags()
#8 /www/core/model/modx/modresource.class.php(498): modResource->parseContent()
#9 /www/core/model/modx/modresponse.class.php(62): modResource->prepare()
#10 /www/core/model/modx/modrequest.class.php(138): modResponse->outputContent()
#11 /www/core/model/modx/modrequest.class.php(122): modRequest->prepareResponse()
#12 /www/core/model/modx/modx.class.php(1461): modRequest->handleRequest()
#13 /www/index.php(54): modX->handleRequest()
#14 {main}
  thrown in /www/core/components/simplesearch/model/simplesearch/simplesearch.class.php on line 437

Not quite sure what triggers it, but the trace suggests a front-end action.

@halftrainedharry
Copy link

This issue occurs only if the system setting use_multibyte isn't set to Yes and the length of the extract to generate is bigger than the length of the text itself.

The error can be avoided by adding this line

if (strlen($text) <= $length) return $text;

before the line that throws the error:

$pos_end = min(strpos($text, ' ', $length - 1), strpos($text, '.', $length - 1));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants