Skip to content

Commit

Permalink
Fix programName extraction and conditionally add 'path' parameter to …
Browse files Browse the repository at this point in the history
…query string

- Corrected the `extractQueryVars` function to properly handle and return the correct value for `programName`, ensuring that the `+` character is not mistakenly replaced with a space.
- Updated the construction of `programQueryString` to include the `path` parameter only if `encodedPath` is not an empty string.
- These changes improve the accuracy of parameter handling and optimize the query string construction process.
  • Loading branch information
TyroneAEM committed Aug 21, 2024
1 parent 7458a83 commit 62e8f76
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions blocks/gmo-program-details/gmo-program-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ const platformMappings = getMappingArray('platforms');
export default async function decorate(block) {
const encodedSemi = encodeURIComponent(';');
const encodedProgram = encodeURIComponent(programName);
const encodedPath = queryVars.path ? `${encodeURIComponent(queryVars.path)}` : '';

blockConfig = readBlockConfig(block);
// Including path in the query if present
const pathParam = queryVars.path ? `&path=${encodeURIComponent(queryVars.path)}` : '';
const programQueryString = `getProgramDetails${encodedSemi}programName=${encodedProgram}${encodedSemi}programID=${encodeURIComponent(programID)}`;
const programQueryString = `getProgramDetails${encodedSemi}programName=${encodedProgram}${encodedSemi}programID=${encodeURIComponent(programID)}` +
(encodedPath ? `${encodedSemi}path=${encodedPath}` : '');

const deliverableQueryString = `getProgramDeliverables${encodedSemi}programName=${encodedProgram}${encodedSemi}programID=${encodeURIComponent(programID)}`;

Expand Down Expand Up @@ -700,39 +701,14 @@ function attachListener(htmlElement) {
})
}

/* old code
function extractQueryVars() {
const urlStr = window.location.href;
const pnRegex = /.*programName=(.*?)&programID=(.*)/;
const match = urlStr.match(pnRegex);
if (match && match[1] && match[2]) {
const pName = decodeURIComponent(match[1]);
let pID = decodeURIComponent(match[2])
if (pID.endsWith('#')) {
pID = pID.slice(0, -1);
}
return {
programName: pName,
programID: pID
}
} else {
return {
programName: 'Program Name Not Available',
programID: 'Program ID Not Available'
}
}
}
*/


function extractQueryVars() {
const urlStr = window.location.href;
const pnRegex = /[?&]programName=([^&]+)&programID=([^&]+)(&path=([^&]+))?/;
const match = urlStr.match(pnRegex);
if (match && match[1] && match[2]) {
const pName = decodeURIComponent(match[1].replace(/\+/g, ' '));
let pID = decodeURIComponent(match[2].replace(/\+/g, ' '));
let pPath = match[4] ? decodeURIComponent(match[4].replace(/\+/g, ' ')) : null;
const pName = decodeURIComponent(match[1]); // Removed the replace method
let pID = decodeURIComponent(match[2]);
let pPath = match[4] ? decodeURIComponent(match[4]) : null;
if (pID.endsWith('#')) {
pID = pID.slice(0, -1);
}
Expand Down

0 comments on commit 62e8f76

Please sign in to comment.