Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion wp-react-lib/src/embedded/EmbeddedGateway.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ class EmbeddedGateway extends React.Component {
container = div
}

if (component) {
if (component != null && getComponent(component) === null) {
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The condition checks both component != null and getComponent(component) === null, but this calls getComponent twice (once here and again on line 50). Consider storing the result in a variable to avoid redundant calls.

Copilot uses AI. Check for mistakes.
element.innerHTML = "<h1>Data Viz Error </h1><h4>Component<i> " + component + "</i> not found</h4><br>"
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

Setting innerHTML with unsanitized component name could introduce XSS vulnerabilities if the component variable contains malicious content. Consider using textContent or a safer DOM manipulation method, or sanitize the component value before insertion.

Suggested change
element.innerHTML = "<h1>Data Viz Error </h1><h4>Component<i> " + component + "</i> not found</h4><br>"
// Safely create error message elements
// Remove all children
while (element.firstChild) {
element.removeChild(element.firstChild);
}
const h1 = document.createElement("h1");
h1.textContent = "Data Viz Error";
element.appendChild(h1);
const h4 = document.createElement("h4");
h4.textContent = "Component ";
const i = document.createElement("i");
i.textContent = component;
h4.appendChild(i);
h4.appendChild(document.createTextNode(" not found"));
element.appendChild(h4);
element.appendChild(document.createElement("br"));

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

} else if (component && getComponent(component)) {
const props = {...this.props}
const attrs = element.attributes
for (let i = attrs.length - 1; i >= 0; i--) {
props[attrs[i].name] = attrs[i].value;
}

element.getAttributeNames().forEach((name) => {
if (name.startsWith('data-')) {
element.removeAttribute(name);
}
});
const C = injectIntl(getComponent(component));
if (C) {
ReactDOM.createRoot(container)
Expand Down
5 changes: 5 additions & 0 deletions wp-react-lib/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const localReplaceLink = (url, locale) => {
if (!pathname.startsWith("/wp/")) {
return url; // Not a WordPress path, leave unchanged
}
//ensuring access to media library files
if (pathname.startsWith("/wp/wp-content")){
return url
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

Missing semicolon at the end of the return statement. While JavaScript has automatic semicolon insertion, this is inconsistent with the style used elsewhere in the file (e.g., line 17).

Suggested change
return url
return url;

Copilot uses AI. Check for mistakes.
}

const afterWp = pathname.slice(3); // remove '/wp'

Expand All @@ -38,6 +42,7 @@ export const replaceLink = (url, locale) => {
}

export const replaceHTMLinks = (html, locale) => {
debugger;
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The debugger statement should be removed before merging to production. This will cause the browser to pause execution in development tools, which is not intended for production code.

Suggested change
debugger;

Copilot uses AI. Check for mistakes.
//console.log("--------- replaceHTMLinks--------------")
// console.log(process.env.REACT_APP_WP_HOSTS)

Expand Down