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

Commit

Permalink
Merge pull request #160 from jkuester/159-fix-native-numbers
Browse files Browse the repository at this point in the history
Prevent conversion of native number params to Scientific Notation
  • Loading branch information
lognaturel committed Sep 16, 2022
2 parents fd05a1b + be3d0b2 commit 4316e52
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/extended-xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module.exports = function(wrapped, extensions) {
case 'num':
if (arg.v === Infinity) argString += '( 1 div 0)';
else if(arg.v === -Infinity) argString += '(-1 div 0)';
else argString += arg.v;
else argString += arg.v.toFixed(20); // Prevent JS from converting to scientific notation
break;
case 'str': {
const quote = arg.quote || (arg.v.indexOf('"') === -1 ? '"' : "'");
Expand Down
1 change: 1 addition & 0 deletions test/integration/native/ceiling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('ceiling', () => {
assertNumberValue("ceiling(5)", 5);
assertNumberValue("ceiling(1.00)", 1);
assertNumberValue("ceiling(-1.05)", -1);
assertNumberValue('ceiling(0.0000001)', 1);
});

it('ceiling() fails when too many arguments are provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('#floor()', () => {
assertNumberValue('floor(5)', 5);
assertNumberValue('floor(1.00)', 1);
assertNumberValue('floor(-1.005)', -2);
assertNumberValue('floor(0.0000001)', 0);
});

it('floor() fails when too many arguments are provided', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/extended-xpath.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ var DATE_MATCH = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug
'native_function()':
/^<xpath:native_function\(\)>$/,
'native_function(3)':
/^<xpath:native_function\(3\)>$/,
/^<xpath:native_function\(3.00000000000000000000\)>$/,
'native_function("string-arg")':
/^<xpath:native_function\("string-arg"\)>$/,
'native_function(\'string-with-escaped-"-arg\')':
/^<xpath:native_function\('string-with-escaped-"-arg'\)>$/,
'native_function(1, 2, 3, "a", \'b\', "c")':
/^<xpath:native_function\(1,2,3,"a",'b',"c"\)>$/,
/^<xpath:native_function\(1.00000000000000000000,2.00000000000000000000,3.00000000000000000000,"a",'b',"c"\)>$/,
'native-function()':
/^<xpath:native-function\(\)>$/,
'native-function(3)':
/^<xpath:native-function\(3\)>$/,
/^<xpath:native-function\(3.00000000000000000000\)>$/,
'native-function("string-arg")':
/^<xpath:native-function\("string-arg"\)>$/,
'native-function(1, 2, 3, "a", \'b\', "c")':
/^<xpath:native-function\(1,2,3,"a",'b',"c"\)>$/,
/^<xpath:native-function\(1.00000000000000000000,2.00000000000000000000,3.00000000000000000000,"a",'b',"c"\)>$/,
/*
// Not clear what to do here as correcting this requires knowledge of return types of native functions.
'native-function1(native-function2() + native-function3()) + native-function4(native-function5() + native-function6())':
Expand Down

0 comments on commit 4316e52

Please sign in to comment.