jsonapi-mapper icon indicating copy to clipboard operation
jsonapi-mapper copied to clipboard

Link formation should consider cases for string literal with spaces and encode them

Open jrcastillo opened this issue 9 years ago • 4 comments

I've encountered an issue when the links for a json object are created. The code I'm generating forms a json object with a value of:

{
  "payload" : {
    "data": {
        "id": "test for it",
        "type": "tests"
      }
  }
}

after passing this object through the mapper the expected link to be created should be encoded for urls like this:

{
    "data": {
        "id": "test for it",
    },
    "self": "/tests/test%20for%20it"
}

instead it is being created this way

{
    "data": {
        "id": "test for it"
    },
    "self": "/tests/test for it"
}

Is it the expected behavior ?

jrcastillo avatar Aug 16 '16 19:08 jrcastillo

@jrcastillo the result makes sense as we aren't doing any URL encoding. That said, an id with spaces in it like the one your example shows seems a bit odd. Is there a specific reason for doing this?

@ShadowManu @chamini2 can either of you think of a good reason to add extra cycles to URL encode? I personally cannot at this moment.

jamesdixon avatar Aug 16 '16 20:08 jamesdixon

Yes, we are using a primary key of bank module as the id which is a text.

jrcastillo avatar Aug 16 '16 23:08 jrcastillo

Well, the returned url should be escaped. It doesn't seem like a hard fix.

chamini2 avatar Aug 16 '16 23:08 chamini2

True - simple, trivial fix.

@jrcastillo, we'll add this as an enhancement. If you'd like to submit a PR, we'd be grateful!

jamesdixon avatar Aug 18 '16 18:08 jamesdixon