Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MILO][MEP] MEP parameter spoof breaks if chosen experience has a comma #1992

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian
if (config.mep?.override) {
let manifest;
/* c8 ignore start */
config.mep?.override?.split(',').some((item) => {
config.mep?.override?.split('---').some((item) => {
const pair = item.trim().split('--');
if (pair[0] === manifestPath && pair.length > 1) {
[, manifest] = pair;
Expand Down Expand Up @@ -606,6 +606,7 @@ function compareExecutionOrder(a, b) {
export function cleanAndSortManifestList(manifests) {
const manifestObj = {};
manifests.forEach((manifest) => {
if (!manifest) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the use-case here? Can manifests contain falsy values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, my sample page was producing an array with a length of 3 (2 manifests and an "empty" manifest). Hadn't seen it before, but decided to add this line to protect from other pages having the same issue.

manifest.manifestPath = normalizePath(manifest.manifestUrl || manifest.manifest);
if (manifest.manifestPath in manifestObj) {
let fullManifest = manifestObj[manifest.manifestPath];
Expand Down
4 changes: 2 additions & 2 deletions libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function updatePreviewButton() {
});

const simulateHref = new URL(window.location.href);
simulateHref.searchParams.set('mep', manifestParameter.join(','));
simulateHref.searchParams.set('mep', manifestParameter.join('---'));

const mepHighlightCheckbox = document.querySelector(
'.mep-popup input[type="checkbox"]#mepHighlightCheckbox',
Expand Down Expand Up @@ -203,7 +203,7 @@ function createPreviewPill(manifests) {
const personalizationOn = getMetadata('personalization');
const personalizationOnText = personalizationOn && personalizationOn !== '' ? 'on' : 'off';
const simulateHref = new URL(window.location.href);
simulateHref.searchParams.set('manifest', manifestParameter.join(','));
simulateHref.searchParams.set('manifest', manifestParameter.join('---'));

const config = getConfig();
let mepHighlightChecked = '';
Expand Down
2 changes: 2 additions & 0 deletions test/features/personalization/preview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ describe('preview feature', () => {
expect(document.querySelector('input#mepHighlightCheckbox').getAttribute('checked')).to.equal('checked');
});
it('updates preview button', () => {
expect(document.querySelector('a[title="Preview above choices"]').getAttribute('href')).to.contain('---');
document.querySelector('#new-manifest').value = 'https://main--homepage--adobecom.hlx.live/homepage/fragments/mep/new-manifest.json';
document.querySelector('input[name="/homepage/fragments/mep/selected-example.json"][value="default"]').click();
expect(document.querySelector('a[title="Preview above choices"]').getAttribute('href')).to.contain('new-manifest.json');
Expand All @@ -193,6 +194,7 @@ describe('preview feature', () => {
expect(document.querySelector('a[title="Preview above choices"]').getAttribute('href')).to.not.contain('mepHighlight');
document.querySelector('input#mepPreviewButtonCheckbox').click();
expect(document.querySelector('a[title="Preview above choices"]').getAttribute('href')).to.contain('mepButton=off');
expect(document.querySelector('a[title="Preview above choices"]').getAttribute('href')).to.contain('---');
});
it('opens manifest', () => {
document.querySelector('a.mep-edit-manifest').click();
Expand Down
Loading