-
Notifications
You must be signed in to change notification settings - Fork 248
fix(rest): Encode table names in UTF-8 in REST paths #2074
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,43 @@ func TestSplitIdentForPathRequiresNamespaceAndName(t *testing.T) { | |
| require.NoError(t, err) | ||
| assert.Equal(t, "parent%1Fnamespace", ns) | ||
| assert.Equal(t, "table", tbl) | ||
|
|
||
| ns, tbl, err = cat.splitIdentForPath(table.Identifier{"namespace+name", "table+name"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "namespace%2Bname", ns) | ||
| assert.Equal(t, "table%2Bname", tbl) | ||
|
|
||
| for name, split := range map[string]func(table.Identifier) (string, string, error){ | ||
| "view": cat.splitViewIdentForPath, | ||
| "function": cat.splitFunctionIdentForPath, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| ns, object, err := split(table.Identifier{"namespace+name", name + "+name"}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "namespace%2Bname", ns) | ||
| assert.Equal(t, name+"%2Bname", object) | ||
| }) | ||
|
Comment on lines
+90
to
+99
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These only check what the split helpers return, so nothing checks that request bodies stay raw. That gap is how the view regression got through. Please add a |
||
| } | ||
| } | ||
|
|
||
| func TestEncodePathSegment(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| value string | ||
| want string | ||
| }{ | ||
| {name: "space", value: " ", want: "%20"}, | ||
| {name: "plus", value: "+", want: "%2B"}, | ||
| {name: "percent", value: "%", want: "%25"}, | ||
| {name: "slash", value: "/", want: "%2F"}, | ||
| {name: "unicode", value: "£€", want: "%C2%A3%E2%82%AC"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| assert.Equal(t, tt.want, encodePathSegment(tt.value)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestLoadRegisteredCatalogRejectsInvalidAuthURL(t *testing.T) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now returns the encoded name, but
CreateView,UpdateViewandRegisterViewstill put that return value into the JSON body. Before this PR they sent the raw name.Repro on 141d7b2 with
table.Identifier{"ns", "my view+x"}:UpdateViewsendsPOST /v1/namespaces/ns/views/my%20view%2Bxwith"identifier":{"namespace":["ns"],"name":"my%20view%2Bx"}RegisterViewsends"name":"my%20view%2Bx"UpdateTable/RegisterTablecorrectly send"name":"my view+x"So
CreateView/RegisterViewwould create a view literally namedmy%20view%2Bx, andUpdateView's body identifier no longer matches its path.Fix: do what you already did for tables. Use
ns, _, err :=inCreateView/RegisterViewand passcatalog.ObjectNameFromIdent(identifier)as the name. InUpdateView, rename the second return toencodedView, use it only inreqPath, and use the raw name inrestIdentifier.