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

fixes core#4047 - htmlspecialchars called on empty array #356

Merged
merged 1 commit into from
Dec 27, 2022

Conversation

MegaphoneJon
Copy link
Contributor

Full details on https://lab.civicrm.org/dev/core/-/issues/4047, but basically - we are sometimes passing empty arrays to this function. Seems like the other instances that were changed on #346 will always be strings, unlike this one.

@civibot
Copy link

civibot bot commented Dec 22, 2022

(Standard links)

@civibot civibot bot added the master label Dec 22, 2022
HTML/Common.php Outdated
@@ -141,7 +141,7 @@ function _getAttrString($attributes)
if (is_array($attributes)) {
$charset = HTML_Common::charset();
foreach ($attributes as $key => $value) {
$strAttr .= ' ' . $key . '="' . htmlspecialchars(($value ?? ''), ENT_COMPAT, $charset) . '"';
$strAttr .= ' ' . $key . '="' . htmlspecialchars(($value ?: ''), ENT_COMPAT, $charset) . '"';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0 a possible legit value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - good point. I can't say definitively but I'll account for that.

@MegaphoneJon MegaphoneJon force-pushed the htmlspecialchars-php81 branch from ad6f08b to 4bf4eca Compare December 22, 2022 17:48
HTML/Common.php Outdated
@@ -141,7 +141,7 @@ function _getAttrString($attributes)
if (is_array($attributes)) {
$charset = HTML_Common::charset();
foreach ($attributes as $key => $value) {
$strAttr .= ' ' . $key . '="' . htmlspecialchars(($value ?? ''), ENT_COMPAT, $charset) . '"';
$strAttr .= ' ' . $key . '="' . htmlspecialchars((is_array($value) ? '' : $value ?? ''), ENT_COMPAT, $charset) . '"';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MegaphoneJon just for the sake of clarity are you able to put ( and ) around the $value ?? '' in the false part of the first ternary operator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @seamuslee001, just saw this.

@MegaphoneJon MegaphoneJon force-pushed the htmlspecialchars-php81 branch from 4bf4eca to 67d6294 Compare December 27, 2022 03:31
@seamuslee001
Copy link
Contributor

thanks @MegaphoneJon

@seamuslee001 seamuslee001 merged commit 01f381d into civicrm:master Dec 27, 2022
@MegaphoneJon MegaphoneJon deleted the htmlspecialchars-php81 branch January 19, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants