Skip to content

WESTMIDLANDS JAN ITP|SEGUN FOLAYAN|DATA-GROUPS|SPRINT-2 #475

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

segunfolayan
Copy link

@segunfolayan segunfolayan commented Mar 31, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@segunfolayan segunfolayan added the Needs Review Participant to add when requesting review label Mar 31, 2025
@segunfolayan segunfolayan changed the title WESTMIDLANDS JAN ITP|SEGUN FOLAYAN WESTMIDLANDS JAN ITP|SEGUN FOLAYAN|SPRINT-2 Mar 31, 2025
@segunfolayan segunfolayan changed the title WESTMIDLANDS JAN ITP|SEGUN FOLAYAN|SPRINT-2 WESTMIDLANDS JAN ITP|SEGUN FOLAYAN|DATA-GROUPS|SPRINT-2 Mar 31, 2025
@@ -6,8 +6,10 @@ function parseQueryString(queryString) {
const keyValuePairs = queryString.split("&");

for (const pair of keyValuePairs) {
const [key, value] = pair.split("=");
queryParams[key] = value;
const [key, ...value] = pair.split("=");
Copy link

Choose a reason for hiding this comment

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

Good job!
In the real world, URLs are usually encoded with percent encoding to represent special characters. In URL, & can be used as a separator (key=value&key=value...) or special character within a key or value. if we were to use & as a special character, we need to encode it.

Can you refactor the code so that parseQueryString("a%25b=c%26d") results in { "a%b": "c&d" }?
FYI, %25 is same as %, %26 is same as &

Copy link
Author

Choose a reason for hiding this comment

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

function parseQueryString(queryString) {
const queryParams = {};
if (queryString.length === 0) {
return queryParams;
}

const keyValuePairs = queryString.split("&");

for (const pair of keyValuePairs) {

const decodedPair = decodeURIComponent(pair);


const [key, ...value] = decodedPair.split("=");
const newValue = value.join("=");

// Store the decoded key and value in the queryParams object
queryParams[key] = newValue;

}

return queryParams;
}

module.exports = parseQueryString;

Copy link
Author

Choose a reason for hiding this comment

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

Thank you

@day-lee day-lee added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Apr 8, 2025
@segunfolayan segunfolayan added the Complete Participant to add when work is complete and review comments have been addressed label Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants