From cfbd3bd3a88e7705dcbd580e2df99b86279c9fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 6 Mar 2024 19:19:22 +0100 Subject: [PATCH] Website: Support Base64-encoding Blueprints passed in the URL Blueprints contain many symbols that need to be URLencoded and posting complex Blueprints on sites like GitHub poses double encoding and formatting challenges. This PR adds support for Base64-encoded Blueprints. ## Testing instructions Go to http://localhost:5400/website-server/#eyJzaXRlT3B0aW9ucyI6eyJibG9nbmFtZSI6IkJhc2U2NCBlbmNvZGluZyB3b3JrcyJ9fQ== and confirm the site title says "Base64 encoding works" --- packages/playground/website/cypress/e2e/blueprints.cy.ts | 9 +++++++++ packages/playground/website/src/lib/resolve-blueprint.ts | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/playground/website/cypress/e2e/blueprints.cy.ts b/packages/playground/website/cypress/e2e/blueprints.cy.ts index f42828f188..294458ae2c 100644 --- a/packages/playground/website/cypress/e2e/blueprints.cy.ts +++ b/packages/playground/website/cypress/e2e/blueprints.cy.ts @@ -42,6 +42,15 @@ describe('Blueprints', () => { cy.wordPressDocument().its('body').should('contain.text', 'My Sites'); }); + it('Base64-encoded Blueprints should work', () => { + const blueprint: Blueprint = { + landingPage: '/', + steps: [{ step: 'enableMultisite' }], + }; + cy.visit('/#' + btoa(JSON.stringify(blueprint))); + cy.wordPressDocument().its('body').should('contain.text', 'My Sites'); + }); + it('enableMultisite step should re-activate the importer plugin', () => { const blueprint: Blueprint = { landingPage: '/wp-admin/plugins.php', diff --git a/packages/playground/website/src/lib/resolve-blueprint.ts b/packages/playground/website/src/lib/resolve-blueprint.ts index f39b454362..172db24e24 100644 --- a/packages/playground/website/src/lib/resolve-blueprint.ts +++ b/packages/playground/website/src/lib/resolve-blueprint.ts @@ -22,7 +22,11 @@ export async function resolveBlueprint() { * /#{"landingPage": "/?p=4"} */ try { - blueprint = JSON.parse(fragment); + try { + blueprint = JSON.parse(atob(fragment)); + } catch (e) { + blueprint = JSON.parse(fragment); + } // Allow overriding the preferred versions using query params // generated by the version switchers. if (query.get('php') || query.get('wp')) {