-
-
Notifications
You must be signed in to change notification settings - Fork 102
fix: escape " in check constraint generator #576
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
Conversation
Actually, I think there's still some problems. Let me investigate further before you check on this. |
OK, it's good now, derp! 🤪 |
Actually, we have to handle already escaped double quotes only right? otherwise this effectively unescapes them, turning |
This is one of those things that makes my brain a little dizzy, lol. I want to get the test case right so I can get the implementation correct. Given: check: ~S[title ~= '("\"\\"\\\"\\\\"\\\\\")'] If we replace just odd slashes, we should expect the migration file to have: check: "title ~= '(\"\\"\\"\\\\"\\\\"\\\\\\")'"
Is that right? 😵💫 |
Thinking about it more, the issue is distinguishing quotes from plain slashes? So a better check would be: check: "title ~= '(\"\\\"\\\\\")'" Becomes: "check: \"title ~= '(\\\"\\\\\"\\\\\\\")'\"" |
Thinking about this more, I don't think we need to "fix" this? If you want double quotes in that code, you just need to do |
Well, it's up to you but I do somewhat strongly disagree because it's inconsistent syntax compared to custom statements and fragments. And if you use multiline sigils, it's very strange, and if using something like I agree what I did is an ugly solution, though. Custom statements do this, which bypasses the problem entirely: def up(%{statement: %{up: up, code?: false}}) do
"""
execute(\"\"\"
#{String.trim(up)}
\"\"\")
"""
end Perhaps a simpler refactor to do this instead would be a better middle ground like this: """
create constraint(:#{as_atom(table)}, :#{as_atom(name)}, check: \"\"\"
#{String.trim(check)}#{option(:prefix, schema)}
\"\"\")
""" That would be consistent with the other generators, and sidestep my original mess. |
I'm down with that solution. |
Contributor checklist
Leave anything that you believe does not apply unchecked.