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

Make escaping strings more consistent. #7059

Merged
merged 10 commits into from
Mar 20, 2024
Merged

Conversation

dnwpark
Copy link
Contributor

@dnwpark dnwpark commented Mar 15, 2024

When running the migration described in #5728, the output is changed to:

json output:

{
  Json("{\"parent\": \"m1o72ual7w4vvc5xkdfyigfisoeww7ah5ucwyy45kljbwbtwwwh5ua\", \"complete\": true, \"proposed\": null, \"confirmed\": [\"DROP FUTURE nonrecursive_access_policies;\", \"ALTER TYPE default::User RENAME TO default::Foo;\", \"ALTER TYPE default::Foo {\\n    CREATE REQUIRED PROPERTY year_q: std::str {\\n        CREATE CONSTRAINT std::regexp(r'^\\\\d{4}-\\\\d$');\\n    };\\n};\", \"DROP SCALAR TYPE default::PigFamily;\"]}"),
}

default output:

{
  'DROP FUTURE nonrecursive_access_policies;
ALTER TYPE default::User RENAME TO default::Foo;
ALTER TYPE default::Foo {
    CREATE REQUIRED PROPERTY year_q: std::str {
        CREATE CONSTRAINT std::regexp(r\'^\\d{4}-\\d$\');
    };
};
DROP SCALAR TYPE default::PigFamily;',
}

Note: Json output changes as the backslashes are now escaped as well as the quotes. This behaviour should be more "correct".

@dnwpark dnwpark requested a review from msullivan March 15, 2024 15:54
@dnwpark dnwpark force-pushed the escape-string-consistent branch from e9b7a8b to c1d90b4 Compare March 15, 2024 16:24
@dnwpark dnwpark force-pushed the escape-string-consistent branch from fc5e7a3 to 459995b Compare March 15, 2024 20:12
@@ -140,7 +141,7 @@ async def fast_forward_describe_migration(
interpolations[var_name] = var_value

for stmt in mig['proposed']['statements']:
curddl = stmt['text']
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to have to an add unescape_string here. This is testing exposed behavior; if we update this, we'd need to update our CLI's migration flows, and we'd break any user using this.

@dnwpark dnwpark force-pushed the escape-string-consistent branch from 824678d to 251d3c9 Compare March 15, 2024 22:18

result = result.replace('\'', '\\\'')
result = result.replace('\"', '\\\"')
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer not to escape double quotes

Comment on lines +50 to +54
result = result.replace('\b', '\\b')
result = result.replace('\f', '\\f')
result = result.replace('\n', '\\n')
result = result.replace('\r', '\\r')
result = result.replace('\t', '\\t')
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this table driven?
(Or maybe just not bother)

Copy link
Member

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Failure's just in one of your new tests

@dnwpark dnwpark merged commit 4c37987 into master Mar 20, 2024
23 checks passed
@dnwpark dnwpark deleted the escape-string-consistent branch March 20, 2024 17:45
vpetrovykh pushed a commit that referenced this pull request Mar 27, 2024
* Make escaping strings more consistent.

* Add unescape_string and fix migration tests.

* Fix json when selecting migration description.

* Fix formatting.

* Remove python string escaping json description.

* Add escape for double quote.

* Remove unescape_string.

* Remove separate escape_string function.

* Remove double quote escape.

* Fix test.
vpetrovykh pushed a commit that referenced this pull request Mar 27, 2024
* Make escaping strings more consistent.

* Add unescape_string and fix migration tests.

* Fix json when selecting migration description.

* Fix formatting.

* Remove python string escaping json description.

* Add escape for double quote.

* Remove unescape_string.

* Remove separate escape_string function.

* Remove double quote escape.

* Fix test.
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.

3 participants