Skip to content

Commit af4ab26

Browse files
authored
Merge pull request #239 from plausible/escape_strings_in_js
Fixed: single quotes and ampersands would break syntax in JS on WC product pages
2 parents 0415214 + 787b6de commit af4ab26

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Integrations/WooCommerce.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function track_add_to_cart_on_product_page() {
163163
plausibleAddToCartForm.classList.add('plausible-event-name=<?php echo str_replace( ' ', '+', $this->event_goals[ 'add-to-cart' ] ); ?>');
164164
plausibleAddToCartForm.classList.add('plausible-event-quantity=' + plausibleQuantity.value);
165165
plausibleAddToCartForm.classList.add('plausible-event-product_id=<?php echo $product->get_id(); ?>');
166-
plausibleAddToCartForm.classList.add('plausible-event-product_name=<?php echo str_replace( ' ', '+', $product->get_name( null ) ); ?>');
166+
plausibleAddToCartForm.classList.add('plausible-event-product_name=<?php echo str_replace( [ ' ', '&' ], '+', addslashes( $product->get_name( null ) ) ); ?>');
167167
plausibleAddToCartForm.classList.add('plausible-event-price=<?php echo $product->get_price( null ); ?>');
168168

169169
plausibleQuantity.addEventListener('change', function (e) {

0 commit comments

Comments
 (0)