Skip to content

Conversation

@kurayami07734
Copy link
Contributor

Issue mentioned other reserved words but does not list them.
I also looked in the docs, but did not find any.

What does this PR do?

Added if statement for preventing use of reserved word in question ID

Fixes #1375

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change adds a new database migration
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

@vercel
Copy link

vercel bot commented Oct 23, 2023

@kurayami07734 is attempting to deploy a commit to the formbricks Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added bug Something isn't working formtribe-2023 hacktoberfest complete these issues to gather points for Hacktoberfest labels Oct 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2023

Thank you for following the naming conventions for pull request titles! 🙏

@review-agent-prime
Copy link
Contributor

The new code added in the PR is generally good, but there seems to be a logical error in the condition checking for reserved words. The condition currentValue || "userId" will always evaluate to true because it's checking if currentValue is truthy, or if the string "userId" is truthy (which it always is).

I believe the intention was to check if currentValue is equal to "userId". Here's the corrected code:

} else if (currentValue === "source" || currentValue === "suID" || currentValue === "userId") {
  setCurrentValue(prevValue);
  updateQuestion(questionIdx, { id: prevValue });
  toast.error("ID cannot used reserved words.");
  return;
}

Also, it might be a good idea to put the reserved words in a list and check if currentValue is in that list. This would make the code cleaner and easier to maintain if more reserved words are added in the future:

const reservedWords = ["source", "suID", "userId"];
...
} else if (reservedWords.includes(currentValue)) {
  setCurrentValue(prevValue);
  updateQuestion(questionIdx, { id: prevValue });
  toast.error("ID cannot used reserved words.");
  return;
}

@kurayami07734 kurayami07734 changed the title Added if statement for preventing use of reserved word in question ID fix: Added if statement for preventing use of reserved word in question ID Oct 23, 2023
@kurayami07734
Copy link
Contributor Author

kurayami07734 commented Oct 25, 2023

Please review this issue
@mattinannt @ShubhamPalriwala @jobenjada

@jobenjada jobenjada added this pull request to the merge queue Oct 28, 2023
@jobenjada
Copy link
Member

Works well, thanks!! :)

Merged via the queue into formbricks:main with commit a92189c Oct 28, 2023
kevinkong91 added a commit to kevinkong91/formbricks that referenced this pull request Oct 30, 2023
* main: (28 commits)
  chore: Add Table of Contents to README (formbricks#1427)
  fix: account deletion failing issue (formbricks#1509)
  fix: remove welcome card from email preview (formbricks#1495)
  fix(bug): default role implemented (formbricks#1524)
  fix: changing description of Code Action (formbricks#1522)
  refactor: Migrate activity service (formbricks#1471)
  fix: Error in Docs navigation formbricks#1518 (formbricks#1521)
  feat: dynamic title and description (formbricks#1459)
  fix: Spelling Errors (formbricks#1517)
  fix: added scrollbar whenever overflowed in the settings/profile page (formbricks#1498)
  fix: long url not getting reset after closing modal (formbricks#1502)
  fix: Unexpected Behavior when Toggling Italics in Text Editor and improve clarity of formatting status (formbricks#1506)
  fix: zod pin validation failing (formbricks#1507)
  fix: Error message on Login not shown  (formbricks#1508)
  fix: downgrade nextjs to fix error with react email (formbricks#1516)
  chore: downgrade next version in formbricks-com (formbricks#1513)
  feat: picture selection question (formbricks#1388)
  feat: formtribe leaderboard update as per today (formbricks#1505)
  fix: Added if statement for preventing use of reserved word in question ID (formbricks#1435)
  fix: Disabling Welcome Card leads buggy preview (formbricks#1320)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hacktoberfest complete these issues to gather points for Hacktoberfest hacktoberfest-accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][FormTribe 🔥][100 Points] Question ID should be restricted

2 participants