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

PHP8 breaks passing blank values in api4 #140

Merged
merged 3 commits into from
Feb 11, 2023

Conversation

MegaphoneJon
Copy link
Contributor

Previously, I used this to fix AuthX for sites behind basic auth:

cv api4 Setting.set +v authx_header_cred=

However, in PHP8, this throws an error:

In AbstractPlusParser.php line 68:
                         
  Failed to parse JSON:  

That is because in PHP8, every string is considered to have an empty string at every position in a string.

This checks explicitly for an empty string.

That said - aren't needle and haystack reversed here?

@totten
Copy link
Member

totten commented Feb 11, 2023

Confirmed -- this makes PHP8 behavior match PHP7. 👍 Added another related fix+test. Merging.

strpos('{["\'', $expr[0]) !== FALSE

That said - aren't needle and haystack reversed here?

No, but the conditional here may be unusual. It determines whether $expr[0] (ie the first character) appears in a list of JS/JSON meta-characters ({, [, ", '). So it matches a JSON object, JSON array, or JSON string.

cv api4 Setting.set +v authx_header_cred=

Aside/fun fact/bike-shed -- I'd probably do:

cv vset authx_header_cred=[]

vset and vget are just a little richer. (Ex: try cv vget /authx/ or cv vget -v authx_header_cred)

@totten totten merged commit b13040c into civicrm:master Feb 11, 2023
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

Successfully merging this pull request may close these issues.

2 participants