Skip to content

Commit

Permalink
Add/allow import site gutenberg pr (#1610)
Browse files Browse the repository at this point in the history
## Motivation for the change, related issues

This is related to supporting visual regression testing of Gutenberg PRs
with Playground.
WordPress/gutenberg#62729

Importing content into a Playground makes testing easier. This will
allow the supported `import-site` parameter to be used on this page as
well.

## Implementation details

This change adds a check for a the `import-site` query parameter and
adds a step to the blueprint when it is found.

The link has minimal validation, but I don't believe this creates a
significant security concern. In theory someone could corrupt the
blueprint by directing people to this URL with a malformed query
parameter.

Validating that the parameter is a URL, and not passing the query string
or hash seemed to mitigate the most obvious offenses.

## Testing Instructions (or ideally a Blueprint)

 1. Run locally 
2. Visit `gutenberg.html` with a query parameter `import-site` pointing
to a valid Playground ZIP import.
 3. Confirm that Playground has imported content from ZIP file.
  • Loading branch information
smithjw1 committed Jul 16, 2024
1 parent a7004a5 commit 5046cf3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/playground/website/public/gutenberg.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>

<head>
<title>Gutenberg PR Previewer</title>
<meta charset="utf-8" />
Expand Down Expand Up @@ -34,6 +35,7 @@
gtag('config', 'G-SVTNFCP8T7');
</script>
</head>

<body>
<div id="main">
<!--
Expand Down Expand Up @@ -212,6 +214,24 @@
},
],
};
// If there's a import-site query parameter, pass that to the blueprint
const urlParams = new URLSearchParams(window.location.search);
try {
const importSite = new URL(urlParams.get('import-site'));
if (importSite) {
// Add it as the first step in the blueprint
blueprint.steps.unshift({
step: 'importWordPressFiles',
wordPressFilesZip: {
resource: 'url',
url: importSite.origin + importSite.pathname,
},
});
}
} catch {
console.error('Invalid import-site URL');
}

const encoded = JSON.stringify(blueprint);
window.location = '/#' + encodeURI(encoded);
}
Expand Down

0 comments on commit 5046cf3

Please sign in to comment.