-
Notifications
You must be signed in to change notification settings - Fork 8
fix(pgsql): Escape Cypher Characters in Literals - BED-7883 #71
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
Open
LawsonWillard
wants to merge
4
commits into
main
Choose a base branch
from
BED-7883
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+308
−3
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
653c2fc
escape special characters in string literals
LawsonWillard c99ba25
Merge branch 'main' of github.com:SpecterOps/DAWGS into BED-7883
LawsonWillard ac616cc
fix(pgsql): equality match against properties containing backslashes …
LawsonWillard 1a4e2f9
update doc
LawsonWillard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package translate | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDecodeCypherStringLiteral(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| type expected struct { | ||
| value string | ||
| errContains string | ||
| } | ||
| type testData struct { | ||
| name string | ||
| raw string | ||
| expected expected | ||
| } | ||
|
|
||
| tt := []testData{ | ||
| {name: "success_-_empty_single_quoted", raw: `''`, expected: expected{value: ``}}, | ||
| {name: "success_-_empty_double_quoted", raw: `""`, expected: expected{value: ``}}, | ||
| {name: "success_-_single_character", raw: `'a'`, expected: expected{value: `a`}}, | ||
| {name: "success_-_plain_ascii", raw: `'hello world'`, expected: expected{value: `hello world`}}, | ||
| {name: "success_-_double_quoted_plain", raw: `"hello"`, expected: expected{value: `hello`}}, | ||
|
|
||
| {name: "success_-_escaped_backslash", raw: `'a\\b'`, expected: expected{value: `a\b`}}, | ||
| {name: "success_-_leading_backslash", raw: `'\\foo'`, expected: expected{value: `\foo`}}, | ||
| {name: "success_-_trailing_backslash", raw: `'foo\\'`, expected: expected{value: `foo\`}}, | ||
| {name: "success_-_only_backslash", raw: `'\\'`, expected: expected{value: `\`}}, | ||
| {name: "success_-_two_consecutive_backslashes", raw: `'\\\\'`, expected: expected{value: `\\`}}, | ||
|
|
||
| {name: "success_-_escaped_single_quote_in_single_quoted", raw: `'O\'Brien'`, expected: expected{value: `O'Brien`}}, | ||
| {name: "success_-_escaped_double_quote_in_double_quoted", raw: `"say \"hi\""`, expected: expected{value: `say "hi"`}}, | ||
| {name: "success_-_escaped_double_quote_in_single_quoted", raw: `'a\"b'`, expected: expected{value: `a"b`}}, | ||
| {name: "success_-_escaped_single_quote_in_double_quoted", raw: `"a\'b"`, expected: expected{value: `a'b`}}, | ||
|
|
||
| {name: "success_-_newline_escape", raw: `'a\nb'`, expected: expected{value: "a\nb"}}, | ||
| {name: "success_-_carriage_return_escape", raw: `'a\rb'`, expected: expected{value: "a\rb"}}, | ||
| {name: "success_-_tab_escape", raw: `'a\tb'`, expected: expected{value: "a\tb"}}, | ||
| {name: "success_-_backspace_escape", raw: `'a\bb'`, expected: expected{value: "a\bb"}}, | ||
| {name: "success_-_form_feed_escape", raw: `'a\fb'`, expected: expected{value: "a\fb"}}, | ||
|
|
||
| {name: "success_-_uppercase_newline_escape", raw: `'a\Nb'`, expected: expected{value: "a\nb"}}, | ||
| {name: "success_-_uppercase_tab_escape", raw: `'a\Tb'`, expected: expected{value: "a\tb"}}, | ||
|
|
||
| {name: "success_-_mssql_style_domain_object_id", raw: `'TEST\\PS1-PSV$@A-1-2-34'`, expected: expected{value: `TEST\PS1-PSV$@A-1-2-34`}}, | ||
| {name: "success_-_windows_path", raw: `'C:\\Users\\Admin'`, expected: expected{value: `C:\Users\Admin`}}, | ||
| {name: "success_-_mixed_escapes", raw: `'a\\b\nc\td'`, expected: expected{value: "a\\b\nc\td"}}, | ||
|
|
||
| {name: "success_-_raw_utf8_bmp_codepoint", raw: `'café'`, expected: expected{value: "café"}}, | ||
| {name: "success_-_raw_utf8_supplementary_codepoint", raw: `'😀'`, expected: expected{value: "😀"}}, | ||
| {name: "success_-_raw_utf8_double_quoted", raw: `"日本語"`, expected: expected{value: "日本語"}}, | ||
|
|
||
| {name: "error_-_empty_input", raw: ``, expected: expected{errContains: "invalid cypher string literal"}}, | ||
| {name: "error_-_single_quote_only", raw: `'`, expected: expected{errContains: "invalid cypher string literal"}}, | ||
| {name: "error_-_no_surrounding_quotes", raw: `foo`, expected: expected{errContains: "missing or mismatched surrounding quotes"}}, | ||
| {name: "error_-_unmatched_quote_styles", raw: `'foo"`, expected: expected{errContains: "missing or mismatched surrounding quotes"}}, | ||
| {name: "error_-_only_open_quote_with_text", raw: `'foo`, expected: expected{errContains: "missing or mismatched surrounding quotes"}}, | ||
| {name: "error_-_only_close_quote_with_text", raw: `foo'`, expected: expected{errContains: "missing or mismatched surrounding quotes"}}, | ||
| {name: "error_-_backtick_quoted", raw: "`foo`", expected: expected{errContains: "missing or mismatched surrounding quotes"}}, | ||
| {name: "error_-_dangling_backslash", raw: `'foo\'`, expected: expected{errContains: "dangling escape"}}, | ||
| {name: "error_-_invalid_escape_letter", raw: `'\x'`, expected: expected{errContains: `invalid escape \x`}}, | ||
| {name: "error_-_invalid_escape_digit", raw: `'\1'`, expected: expected{errContains: `invalid escape \1`}}, | ||
| {name: "error_-_bare_backslash_before_letter", raw: `'a\Pb'`, expected: expected{errContains: `invalid escape \P`}}, | ||
| {name: "error_-_lowercase_unicode_escape_unsupported", raw: `'\u0041'`, expected: expected{errContains: `invalid escape \u`}}, | ||
| {name: "error_-_uppercase_unicode_escape_unsupported", raw: `'\U0001F600'`, expected: expected{errContains: `invalid escape \U`}}, | ||
| } | ||
|
|
||
| for _, testCase := range tt { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| if got, err := decodeCypherStringLiteral(testCase.raw); testCase.expected.errContains != "" { | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), testCase.expected.errContains) | ||
| } else { | ||
| require.NoError(t, err) | ||
| assert.Equal(t, testCase.expected.value, got) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.