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

there is some problem with the function "encode_string_as_pointer"!!!!! #439

Closed
AIChangjiang opened this issue Mar 9, 2020 · 4 comments
Closed

Comments

@AIChangjiang
Copy link

it shoud change "~" to "0",but this function has change "" to "~1", there also have problem with the "/";
the right implement may be as follow.

static void encode_string_as_pointer(unsigned char *destination, const unsigned char *source)
{
for (; source[0] != '\0'; (void)source++, destination++)
{
if (source[0] == '/')
{
destination[1] = '';
destination[1] = '1';
destination++;
}
else if (source[0] == '
')
{
destination[0] = '~';
destination[1] = '0';
destination++;
}
else
{
destination[0] = source[0];
}
}

destination[0] = '\0';

}

@Alanscut
Copy link
Collaborator

Alanscut commented Mar 17, 2020

Hi, @AIChangjiang , can you provide more information about it, what would happen if not change the original implementation and what bug you occurred when use this function.

@AIChangjiang
Copy link
Author

AIChangjiang commented Mar 17, 2020

Hello. Thank you for your reply.
I had a problem when getting the JSON PONTER,For example, there is a json body like this
{"m~n", "test"}
I will get the json poniter "/m~1n",according to the rfc6901,i should get the result is "/m~0n",
so i think the function encode_string_as_pointer is something wrong.

@Alanscut
Copy link
Collaborator

Hi @AIChangjiang , yes, you are right. encode_string_as_pointer seems has some problem according to the rfc6901.

Here is a snippet I extracted from the rfc6901 document:

   A JSON Pointer is a Unicode string (see [RFC4627], Section 3)
   containing a sequence of zero or more reference tokens, each prefixed
   by a '/' (%x2F) character.

   Because the characters '~' (%x7E) and '/' (%x2F) have special
   meanings in JSON Pointer, '~' needs to be encoded as '~0' and '/'
   needs to be encoded as '~1' when these characters appear in a
   reference token.

According to this, I think the right implement may be as follow:

static void encode_string_as_pointer(unsigned char *destination, const unsigned char *source)
{
    for (; source[0] != '\0'; (void)source++, destination++)
    {
        if (source[0] == '/')
        {
            destination[0] = '~';
            destination[1] = '1';
            destination++;
        }
        else if (source[0] == '~')
        {
            destination[0] = '~';
            destination[1] = '0';
            destination++;
        }
        else
        {
            destination[0] = source[0];
        }
    }

    destination[0] = '\0';
}

What's you opinion?

@AIChangjiang
Copy link
Author

yes, I think your modifications are correct. That's what I thought.
Thanks for your attention.

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

No branches or pull requests

2 participants