opengeek / getResources

A MODx Snippet for iterating a collection of MODx Resources
http://rtfm.modx.com/display/ADDON/getResources
27 stars 22 forks source link

Update snippet.getresources.php #112

Closed weitblick closed 21 hours ago

weitblick commented 1 day ago

fix php 8 error if $filter <= 1

opengeek commented 1 day ago

Thanks for the contribution. Can you provide information on how you called getResources to trigger the error and details on the error being produced?

weitblick commented 1 day ago

I generated the error via an unclean &tvFilters=`` (|| at the end). I suspect that this was also the case with the other errors from https://github.com/opengeek/getResources/issues/111

[[getResources?
  ...
  &limit=`1`
  &includeTVs=`1`
  &processTVs=`1`
  &sortby=`{"publishedon":"DESC"}`
  &tvFilters=`tagVisibleTV==%1%,tagMainTV==%Kloster%||`
  &where=`{"template:=":5}`
]]

The error occurs because the strpos() function in the PHP script tries to search for a string in another string, but the start offset (argument #3, $offset) is not within the search string (argument #1, $haystack). If the offset is greater than the length of the string or is negative, PHP throws a ValueError since version 8.0.