digitoimistodude / air-cookie

13 stars 2 forks source link

Filters for specific keys are string templated incorrectly #10

Open raikasdev opened 3 months ago

raikasdev commented 3 months ago

Because we use backslashes and not normal slashes, this escapes the complex string templating and results in the wrong filter name:

$strings[ $key ] = apply_filters( "air_cookie\strings\{$key}", $string );

with key consent_modal_title results in a filter "air_cookie\strings\{consent_modal_title}" being applied.

Proper usage would be

$strings[ $key ] = apply_filters( "air_cookie\strings\\{$key}", $string );

As seen on PHP String docs "Complex (curly) syntax" in the last 5 lines of the first code example.

// Won't work, outputs: C:\folder\{fantastic}.txt
echo "C:\folder\{$great}.txt"
// Works, outputs: C:\folder\fantastic.txt
echo "C:\\folder\\{$great}.txt"
raikasdev commented 3 months ago

Noticed first by @rahkapetteri here.

Seems like I just scanned the message without reading it with thought :face_with_spiral_eyes:, but thanks for pointing this out! Noticed it today when setupping air-cookie for a site.