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

Data isn't saved if user input contains quotes #13

Open
radumas opened this issue Sep 30, 2019 · 2 comments
Open

Data isn't saved if user input contains quotes #13

radumas opened this issue Sep 30, 2019 · 2 comments
Assignees
Labels

Comments

@radumas
Copy link
Owner

radumas commented Sep 30, 2019

Discovered this with some feedback from a fork of this. From mentalhealthawhereness/map#1

I tried inserting a note that read I'm here... and the console revealed an error message

POST https://anditabinas.carto.com/api/v2/sql 400 (Bad Request)
(index):206 Problem saving the data

The sql that is being generated here is something like `SELECT insert_data('I'm here');' The issue is in where the sql string to get passed to the Carto sql API is being generated by simple string manipulation https://github.com/mentalhealthawhereness/map/blob/master/index.html#L199-210

A simple fix would be to replace any single-quote with the Postgresql-friendly doubled single quote SELECT insert_data('I''m here'); (see ex below) but I wonder if there's a.... better way of solving more cases of user-input that could break this. So I asked on StackOverflow

sanitized_input = user_input.replace("'", "''")
@radumas radumas added the bug label Sep 30, 2019
@radumas radumas self-assigned this Sep 30, 2019
@radumas
Copy link
Owner Author

radumas commented Oct 8, 2019

Single quotes works, saves successfully.
image

Not super certain what to do about double quotes (did not save)

Screenshot 2019-10-07 at 22 04 20

@radumas radumas reopened this Oct 8, 2019
radumas added a commit that referenced this issue Oct 8, 2019
@radumas
Copy link
Owner Author

radumas commented Oct 8, 2019

JSON.stringify() fixes double-quotes.
Dunno how to handle double single-quotes though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant