Skip to content

fix: ignore commented out code when giving warning in SQL editor#16511

Merged
gregnr merged 5 commits intosupabase:masterfrom
kishanhitk:fix-16484
Aug 21, 2023
Merged

fix: ignore commented out code when giving warning in SQL editor#16511
gregnr merged 5 commits intosupabase:masterfrom
kishanhitk:fix-16484

Conversation

@kishanhitk
Copy link
Contributor

@kishanhitk kishanhitk commented Aug 14, 2023

Fixes: #16484

What does it solve?

The SQL editor warns whenever the SQL command contains any of these keywords: drop, delete, and truncate. But the warning shows even if these keywords are part of a commented-out code section.

Solution logic:

We use a regex to match if the SQL contains any of those words. I have added an extra function that removes the commented-out code before matching it to the regex.

Alternate solution:

We can update the regex itself to ignore the commented-out code. But, it was getting complex, so I opted for the above approach.

Limitation:

The function to remove commented out code does not work as expected when there is a nested comment.

@vercel
Copy link

vercel bot commented Aug 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 7:38pm
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 7:38pm
studio-self-hosted ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 7:38pm
studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 7:38pm
zone-www-dot-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 7:38pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
ui-storybook ⬜️ Ignored (Inspect) Visit Preview Aug 21, 2023 7:38pm

@vercel
Copy link

vercel bot commented Aug 14, 2023

@kishanhitk is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@kishanhitk kishanhitk marked this pull request as ready for review August 15, 2023 10:26
@kishanhitk kishanhitk requested a review from a team as a code owner August 15, 2023 10:26
@kishanhitk
Copy link
Contributor Author

There is an npm package, pg-minify. It claims to remove all types of comments, including nested comments.
But, a few points:

  • The weekly download number is not that good.
  • Using an npm package only for this small use case, which is not very critical, may not be a good idea.

Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commented out destructive actions in SQL Editor on supabase.com create a warning

2 participants