Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 18 files. Only the first 5 are listed here.
If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
anomiex
left a comment
There was a problem hiding this comment.
Overall, looks reasonable. Haven't tested at all.
Something else you may want to double check is whether any downstream uses of the JS vars were expecting PHP to have HTML-escaped them, since CRM does a lot of building of HTML strings in JS. Then again, maybe we already took care of those in #48390. 😀
| } | ||
|
|
||
| echo esc_html( $labelK ) . ":'" . esc_html( zeroBSCRM_slashOut( $labelV ) ) . "'"; | ||
| echo esc_html( $labelK ) . ':' . wp_json_encode( $labelV, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); |
There was a problem hiding this comment.
| echo esc_html( $labelK ) . ':' . wp_json_encode( $labelV, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); | |
| echo wp_json_encode( $labelK, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ':' . wp_json_encode( $labelV, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); |
Or really, though, you could replace this whole block with
var zbsEditViewLangLabels = <?php echo wp_json_encode(
array_merge(
array(
'today' => __( 'Today', 'zero-bs-crm' ),
),
$this->langLabels
),
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
); ?>;
There was a problem hiding this comment.
Yep, this is a case where I held back (part of that refactor note in the description). 😄 I've done similar things in other places in the CRM for language arrays. But not today.
There was a problem hiding this comment.
On second thought, I'll adjust this for better readability, as I've found several other such instances. 😄
| <?php | ||
| #} Nonce for AJAX | ||
| echo "var zbscrmjs_secToken = '" . esc_js( wp_create_nonce( 'zbscrmjs-ajax-nonce' ) ) . "';"; | ||
| echo 'var zbscrmjs_secToken = ' . wp_json_encode( wp_create_nonce( 'zbscrmjs-ajax-nonce' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';'; | ||
| ?> |
There was a problem hiding this comment.
Seems odd this isn't like
var zbscrmjs_secToken = <?php echo wp_json_encode( wp_create_nonce( 'zbscrmjs-ajax-nonce' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;
like the rest here.
| } | ||
|
|
||
| echo esc_html( $labelK ) . ":'" . esc_html( zeroBSCRM_slashOut( $labelV, true ) ) . "'"; | ||
| echo esc_html( $labelK ) . ':' . wp_json_encode( $labelV, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); |
There was a problem hiding this comment.
Same as above, the simple fix being to also json_encode $labelK and the better fix being an array_merge and letting json_encode do the object.
| } | ||
|
|
||
| echo esc_html( $labelK ) . ":'" . esc_html( zeroBSCRM_slashOut( $labelV ) ) . "'"; | ||
| echo esc_html( $labelK ) . ':' . wp_json_encode( $labelV, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); |
Newlines added in #46809 broke these. Let's one-line them by moving most logic to separate PHP.
9777595 to
eb86b1e
Compare
Proposed changes
This PR updates a few instances that were escaped in a JS context, but not with the proper function. Examples include:
esc_js()→wp_json_encode()or(int)esc_html()→ wp_json_encode()or(int)`parseInt()→(int)zeroBSCRM_slashOut()→wp_json_encode()Note that a lot of this could be refactored, but right now the focus is escaping. I did move several arrays out to PHP so they could be one-lined in JS (avoiding PHPCS hassle).
Also, I found and fixed some more broken JS var regressions from #46809: 143263f
Related product discussion/links
Does this pull request change what data or activity we track or use?
Testing instructions
I guess look at the code. The context should be fairly clear.