Project

General

Profile

Actions

Bug #17582

closed

Cannot assign names that start with '['

Added by Lucas Di Pentima about 3 years ago. Updated almost 3 years ago.

Status:
Resolved
Priority:
Normal
Assigned To:
Category:
API
Target version:
Story points:
-
Release relationship:
Auto

Description

When trying to assign a name that starts with opening square brackets, the API responds with the following error:

invalid character 'X' looking for beginning of value

This seems to be related to JSON lists, so the solution probably should be that wb2 needs to properly encode the [ char.

Workbench1 and the CLI tools don't have this issue.


Subtasks 1 (0 open1 closed)

Task #17592: Review 17582-square-brackets-on-names-fixResolvedLucas Di Pentima05/11/2021Actions

Related issues

Blocks Arvados - Idea #17512: Release Arvados 2.2ResolvedPeter Amstutz05/03/2021Actions
Actions #1

Updated by Lucas Di Pentima about 3 years ago

  • Description updated (diff)
Actions #2

Updated by Lucas Di Pentima almost 3 years ago

  • Status changed from New to In Progress
Actions #3

Updated by Lucas Di Pentima almost 3 years ago

Sending JSON data via curl is working correctly:

$ curl -v -X PUT --data '{"collection":{"name":"[Deprecated]"}}' -H "Authorization: OAuth2 xxxtokenxxx" -H "Content-Type: application/json" https://ce8i5.arvadosapi.com/arvados/v1/collections/ce8i5-4zz18-9m0e1jso8boqqxy

OTOH, Chrome's inspector shows what seems to be a correct request body, for example while creating a new collection

{"name":"{A new coll","description":null,"preserve_version":true}

...so I'm not sure what's going on yet.

Actions #4

Updated by Lucas Di Pentima almost 3 years ago

I've found different behaviors depending on the shape of the passed JSON payload.

This is what wb2 is trying to pass (failing request):

{"name":"[Some name]"}

...but the following does work ok:

{"collection":{"name":"[Some name]"}}

...so I'm wondering now whether this is a client or a backend bug.

Actions #5

Updated by Lucas Di Pentima almost 3 years ago

From chat:

Tom: I suspect it's either controller or rails that needs fixing. foo=[true] and foo="bar" are ambiguous in a form-encoded body, but {"foo":"[bar]"} is not ambiguous in a json-encoded body, so we should be able to handle that correctly.
Suspect part/all of the fix will be making controller use a JSON request body instead of formencoded. I'm not sure why we ever would have used formencoded. I vaguely recall it could be that _method=GET didn't work in a JSON body... if that's the case, maybe we can use the X-Http-Method-Override header instead?

Actions #6

Updated by Lucas Di Pentima almost 3 years ago

  • Target version changed from 2021-04-28 bughunt sprint to 2021-05-12 sprint
Actions #7

Updated by Peter Amstutz almost 3 years ago

  • Category changed from Workbench2 to API
  • Project changed from Arvados Workbench 2 to Arvados
Actions #8

Updated by Peter Amstutz almost 3 years ago

Actions #9

Updated by Tom Clegg almost 3 years ago

in (*lib/controller/router.router)loadRequestParams():

                                // The Ruby "arv" cli tool sends a                                                                                     
                                // JSON-encode params map with                                                                                         
                                // JSON-encoded values.                                                                                                

It seems that in order for "arv" to work, we double-decode a top level params, so this works:

{"properties":"{\"foo\":\"bar\"}"}

...but we don't double-decode lower levels, so this also works:

{"collection":{"name":"{\"foo\":\"bar\"}"}}

fwiw the examples at https://doc.arvados.org/main/api/requests.html put updated fields at lower levels.

Is it really annoying to change workbench2 to send a body like {"collection":{"name":"[foo]"}} instead of {"name":"foo"}?

Other possibilities:
  • detect afflicted versions of Ruby CLI/SDK (via user-agent?), fix current Ruby CLI/SDK, and turn off this weird behavior for normal clients
  • treat malformed JSON as a string, which would probably solve most real-world cases (like "[foo]") but would still break confusingly on other cases (like "[]").
Actions #11

Updated by Lucas Di Pentima almost 3 years ago

Ok, so as suggested by Tom, I fixed it on the wb2 side: arvados-workbench2|c0d7c33 - branch: 17582-square-brackets-on-names-fix
Test run: developer-tests-workbench2: #407

  • Updated the common resource service to send payloads of the form {rsc_name: { data }} instead of just a JSON object with the plain data.
  • Updated tests.
Actions #12

Updated by Lucas Di Pentima almost 3 years ago

Rebased and added integration tests at arvados-workbench2|d1400d7
Test run: developer-tests-workbench2: #409

Actions #13

Updated by Lucas Di Pentima almost 3 years ago

Fixes cypress test to support testing names with {curly braces} at arvados-workbench2|52517c0
Test run: developer-tests-workbench2: #412

Actions #14

Updated by Tom Clegg almost 3 years ago

This LGTM, thanks!

Actions #15

Updated by Lucas Di Pentima almost 3 years ago

  • Status changed from In Progress to Resolved
Actions

Also available in: Atom PDF