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

Added support for non-NaNish base 16 numbers in jsonpath #328

Merged
merged 4 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ node_modules
.lock-wscript

test-page-webpack/dist

*.iml
.idea
4 changes: 1 addition & 3 deletions src/record/json-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,5 @@ function tokenize( path ) {
throw new Error('invalid path ' + path)
}

return cache[ path ] = parts.map( function( part ) {
return !isNaN( part ) ? parseInt( part, 10 ) : part;
} );
return cache[ path ] = parts;
};
10 changes: 10 additions & 0 deletions test-unit/unit/record/json-pathSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ describe( 'objects are created from paths and their value is set correctly', fun
});
});

it( 'even when the path is not NaNish and could be interpreted as a base 16 number', function() {
var record = {};
let pathName = '0x02335';
Copy link
Contributor

Choose a reason for hiding this comment

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

let fails build ( we can put a use strict at the top since this just tests though if you want )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I changed to "var". Thanks!

record = jsonPath.set( record, pathName, 'value' );
expect( record[ 0 ] ).toBe( undefined );
expect( record[ pathName ] ).toBe( 'value' );
expect( jsonPath.get( record, pathName )).toBe( 'value' );
expect( record[ pathName ] ).toBe( 'value' );
})

it( 'extends existing arrays', function(){
var record = {_$data: {
firstname: 'Wolfram',
Expand Down