Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Fix #14: Decoding fails when two encoded characters appear one after another #21

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tholu
Copy link
Contributor

@tholu tholu commented Feb 28, 2019

@FagnerMartinsBrack I accidentally did some small refactoring (simplifications) together with the fix, the actual fix for is in Cookies:316-323.

Please review and merge, thanks!

Resolves #14.

@FagnerMartinsBrack
Copy link
Member

The integration test with js-cookie fails when I checkout 9e305c9:

screen shot 2019-03-01 at 9 02 17 am

Are you getting the same error?

@tholu
Copy link
Contributor Author

tholu commented Mar 1, 2019

@FagnerMartinsBrack Thanks for checking that, I can reproduce it and need to look into it.

@JevinMenezes
Copy link
Contributor

It's been a while here for this PR, wish it could be closed any time soon.

@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Mar 10, 2021

@JevinMenezes If the OP is not continuing to work on this for more than a year then I believe it can be closed.

@tholu
Copy link
Contributor Author

tholu commented Mar 10, 2021

@JevinMenezes @FagnerMartinsBrack Thanks for the reminder! I'll try to finish it soon.

Comment on lines +30 to +36
@Test
public void character_with_2_bytes() {
Mockito.when( request.getHeader( "cookie" ) ).thenReturn( "c=%C3%A3" );
String actual = cookies.get( "c" );
String expected = "ã";
Assert.assertEquals( expected, actual );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is failing.., (its also failing in Travis CI builds - https://travis-ci.org/github/js-cookie/java-cookie/builds/764105675)
java-cookie pr reivew faing junit

@tholu check this failing test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JevinMenezes Yes, I explicitly added the test case here: 88b8327

Thanks for the reminder! Did not have time yet to fix the issue, will try to get this done over the weekend.

@tholu
Copy link
Contributor Author

tholu commented Oct 26, 2021

@JevinMenezes I fixed the test, but Travis is not running anymore?

@JevinMenezes
Copy link
Contributor

JevinMenezes commented Oct 30, 2021

@FagnerMartinsBrack Travis builds for this repository have stopped in travis-ci.org and this repo needs to be migrated to travis-ci.com. Can we migrate java-cookie repo to travis-ci.com ?

@FagnerMartinsBrack
Copy link
Member

@JevinMenezes yes what do you want me to do?

@JevinMenezes
Copy link
Contributor

JevinMenezes commented Oct 31, 2021

Just wanted to ask whether I can approve & request this for organization js-cookie,
Capture
@FagnerMartinsBrack
(I believed organization owner could approve this)

@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Oct 31, 2021 via email

@FagnerMartinsBrack
Copy link
Member

@JevinMenezes I received the email and just approved it, let me know if you need anything else

@JevinMenezes
Copy link
Contributor

JevinMenezes commented Oct 31, 2021

@FagnerMartinsBrack thanks, seems like an admin privilege user can migrate the java-cookie repo and I'm unable to select the repo for migrating to travis-ci.com, would you be able to do it, thanks again ,
image

@FagnerMartinsBrack
Copy link
Member

Done @JevinMenezes

@tholu
Copy link
Contributor Author

tholu commented Nov 9, 2021

@JevinMenezes Can this be merged now? I'll have to fix conflicts in #23 afterwards.

Comment on lines 328 to 347
// Decode characters with 3 bytes first, then with 1 byte to fix https://github.com/js-cookie/java-cookie/issues/14
return decode( decode( encoded, 3 ), 1 );
}

private String decode( String encoded, Integer bytesPerCharacter ) {
// Use URLDecoder to fix https://github.com/js-cookie/java-cookie/issues/14
String decoded = encoded;
Pattern pattern = Pattern.compile( "(%[0-9A-Z]{2}){" + bytesPerCharacter + "}" );
Matcher matcher = pattern.matcher( encoded );
while ( matcher.find() ) {
String encodedChar = matcher.group();
String[] encodedBytes = encodedChar.split( "%" );
byte[] bytes = new byte[ encodedBytes.length - 1 ];
for ( int i = 1; i < encodedBytes.length; i++ ) {
String encodedByte = encodedBytes[ i ];
bytes[ i - 1 ] = ( byte )Integer.parseInt( encodedByte, 16 );
}
try {
String decodedChar = new String( bytes, UTF_8 );
decoded = decoded.replace( encodedChar, decodedChar );
} catch ( UnsupportedEncodingException e ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tholu I see that decode implementation with 3 bytes first and then with 1 byte is for fixing #14 , further the issue also mentions #14 (comment) . Will this change in implementation solve #14 (comment) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tholu seems like my review wasn't submitted a few days ago, apologies for the same. Could you please update on this #21 (comment), I can update the PR post your reply, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Decoding sometimes fails when two encoded characters appear one after another.
3 participants