You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<div id="smart-button-container">
<div style="text-align: center"><label for="description">Test </label><input type="text" name="descriptionInput" id="description" maxlength="127" value=""></div>
<p id="descriptionError" style="visibility: hidden; color:red; text-align: center;">Please enter a description</p>
<div style="text-align: center"><label for="amount">test amount </label><input name="amountInput" type="number" id="amount" value="" ><span> USD</span></div>
<p id="priceLabelError" style="visibility: hidden; color:red; text-align: center;">Please enter a price</p>
<div id="invoiceidDiv" style="text-align: center; display: none;"><label for="invoiceid">testinvoice </label><input name="invoiceid" maxlength="127" type="text" id="invoiceid" value="" ></div>
<p id="invoiceidError" style="visibility: hidden; color:red; text-align: center;">Please enter an Invoice ID</p>
<div style="text-align: center; margin-top: 0.625rem;" id="paypal-button-container"></div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=USD" data-sdk-integration-source="button-factory"></script>
<script>
function initPayPalButton() {
var description = document.querySelector('#smart-button-container #description');
var amount = document.querySelector('#smart-button-container #amount');
var descriptionError = document.querySelector('#smart-button-container #descriptionError');
var priceError = document.querySelector('#smart-button-container #priceLabelError');
var invoiceid = document.querySelector('#smart-button-container #invoiceid');
var invoiceidError = document.querySelector('#smart-button-container #invoiceidError');
var invoiceidDiv = document.querySelector('#smart-button-container #invoiceidDiv');
var elArr = [description, amount];
if (invoiceidDiv.firstChild.innerHTML.length > 1) {
invoiceidDiv.style.display = "block";
}
var purchase_units = [];
purchase_units[0] = {};
purchase_units[0].amount = {};
function validate(event) {
return event.value.length > 0;
}
paypal.Buttons({
style: {
color: 'gold',
shape: 'rect',
label: 'paypal',
layout: 'vertical',
},
onInit: function (data, actions) {
actions.disable();
if(invoiceidDiv.style.display === "block") {
elArr.push(invoiceid);
}
elArr.forEach(function (item) {
item.addEventListener('keyup', function (event) {
var result = elArr.every(validate);
if (result) {
actions.enable();
} else {
actions.disable();
}
});
});
},
onClick: function () {
if (description.value.length < 1) {
descriptionError.style.visibility = "visible";
} else {
descriptionError.style.visibility = "hidden";
}
if (amount.value.length < 1) {
priceError.style.visibility = "visible";
} else {
priceError.style.visibility = "hidden";
}
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
invoiceidError.style.visibility = "visible";
} else {
invoiceidError.style.visibility = "hidden";
}
purchase_units[0].description = description.value;
purchase_units[0].amount.value = amount.value;
if(invoiceid.value !== '') {
purchase_units[0].invoice_id = invoiceid.value;
}
},
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: purchase_units,
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
},
onError: function (err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
Add that to a Custom HTML Block, publish the page, then try viewing the page on a Chromium based browser.
The line:
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
Will get rendered in the browser (Chromium based) as:
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
And in most cases, will not be interpreted on the page properly (so far, it seems hit or miss as to whether a Chromium based browser will show the PayPal buttons). Firefox seems to work without any issues.
Expected behavior
The code added in the Custom HTML Block to be rendered properly
Screenshots
Chrome console errors:
How the page shows in Chrome:
vs how it shows in Firefox:
Editor version (please complete the following information):
WordPress version: 5.5.1
Does the website has Gutenberg plugin installed, or is it using the block editor that comes by default? Both/either.
If the Gutenberg plugin is installed, which version is it? Version 9.0.0
Desktop (please complete the following information):
OS: Windows 10
Browser: Chrome Version 86.0.4240.75 (Official Build) (64-bit) and Edge Version 85.0.564.70 (Official build) (64-bit)
The text was updated successfully, but these errors were encountered:
This was previously reported in #13186, but it's considered a bug in WordPress core (something that can't be fixed in this codebase), so it's being tracked in core trac here - https://core.trac.wordpress.org/ticket/49480.
scosgro
changed the title
Custom HTML Block: Not handling JavaScript properly, escapting unexpectedly
Custom HTML Block: Not handling JavaScript properly, escaping unexpectedly
Oct 9, 2020
Describe the bug
Using a very popular example, create a PayPal Smart Button.
https://www.paypal.com/buttons/smart
The code will look something like this:
Add that to a Custom HTML Block, publish the page, then try viewing the page on a Chromium based browser.
The line:
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
Will get rendered in the browser (Chromium based) as:
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
And in most cases, will not be interpreted on the page properly (so far, it seems hit or miss as to whether a Chromium based browser will show the PayPal buttons). Firefox seems to work without any issues.
Expected behavior
The code added in the Custom HTML Block to be rendered properly
Screenshots


Chrome console errors:
How the page shows in Chrome:

vs how it shows in Firefox:

Editor version (please complete the following information):
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: