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

Strings are not always single quoted #5

Open
alanliang opened this issue Dec 4, 2015 · 3 comments
Open

Strings are not always single quoted #5

alanliang opened this issue Dec 4, 2015 · 3 comments

Comments

@alanliang
Copy link

var a = {name: "Steve&Jobs"};
rison.encode(a)

Actual:

"(name:Steve&Jobs)"

Expected: String with quotes.

"(name:'Steve&Jobs')"

However, quotes are inserted when there is a space in the string:

var b = {name: "Steve&Jobs "};
rison.encode(b)

Actual and Expected:

"(name:'Steve&Jobs ')"

The problem is the encoded value is placed in a URI, there will be trouble decoding it since & will be interfering.

Any reason why we don't quote in certain cases?

string: function (x) {
                if (x == '')
                    return "''";

                if (rison.id_ok.test(x))
                    return x;
@Nanonid
Copy link
Owner

Nanonid commented Apr 16, 2016

This is an excellent candidate for a API validation test. #10

@funseiki
Copy link

I'm running into this as well. Any plans for a fix as of yet?

@5thHorsem4n
Copy link

I found a work around for this issue.
Instead of encodeURIComponent the entire string just encode &. The browser in my case is taking care of the rest.

In my testing it was limited to if there was another property after the string.

Here are my tests:

 var encodeUriText = {
        name: encodeURIComponent(".Black & White"),
        z:1
    };

    var currentWorkAround = {
        name: ".Black & White".replace("&","%26"),
        z:1
    };

    var encodeUriTextExpected = "(name:'.Black%20%26%20White',z:1)";
    var currentEncodeUriTextEncoding = "(name:.Black%20%26%20White,z:1))";

    it('current behavior', function () {


        //Act
        var testObjEncoded = rison.encode(encodeUriText);

        //Assert
        expect(testObjEncoded).to.deep.equal(encodeUriTextExpected);
        expect(testObjEncoded).to.deep.equal(currentEncodeUriTextEncoding);

    });

    it('current work around', function () {


        //Act
        var currentWorkAroundEncoded = rison.encode(currentWorkAround);

        //Assert
        expect(currentWorkAroundEncoded).to.deep.equal("(name:'.Black %26 White',z:1)");

    });

    it('decoding encodeUriTextExpected', function () {


        //Act
        var decoded = rison.decode(encodeUriTextExpected);

        //Assert
        expect(decoded).to.deep.equal(encodeUriText);

    });


    it('current error while decoding string', function () {


        //Act
        var decoded = rison.decode(currentEncodeUriTextEncoding);

        //Assert
        expect(decoded).to.deep.equal(encodeUriText);

    });
    it('seems to work fine', function () {


        //Act
        var decoded = rison.decode("(name:'.Black%20%26%20White')");

        //Assert
        expect(decoded).to.deep.equal({name:'.Black%20%26%20White'});

    });`

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

4 participants