Permalink
Browse files

Fix sort regex to respect sci-notated float number

  • Loading branch information...
SergioCrisostomo authored and anutron committed Jun 20, 2014
1 parent d0d5712 commit bf8b5de63569fb7420c831066dbf777c9b725731
Showing with 7 additions and 2 deletions.
  1. +2 −2 Source/Interface/HtmlTable.Sort.js
  2. +5 −0 Specs/Interface/HtmlTable.Sort.js
@@ -292,7 +292,7 @@ HtmlTable.Parsers = {
type: 'date'
},
'input-checked': {
match: / type="(radio|checkbox)" /,
match: / type="(radio|checkbox)"/,
convert: function(){
return this.getElement('input').checked;
}
@@ -320,7 +320,7 @@ HtmlTable.Parsers = {
'float': {
match: /^[\d]+\.[\d]+/,
convert: function(){
return this.get('text').replace(/[^-?^\d.]/, '').stripTags().toFloat();
return this.get('text').replace(/[^-?^\d.e]/, '').stripTags().toFloat();
},
number: true
},
@@ -101,6 +101,11 @@ describe('HtmlTable.Sort', function(){
expect(sortedTable('float', ['1', '.03', '.2'])).toEqual(['.03', '.2', '1']);
});
it('should correctly sort floats in scientific notation according to value', function(){
expect(sortedTable(false, [1.3e-10, 1.1, 1, 2])).toEqual(['1.3e-10', '1', '1.1', '2']);
expect(sortedTable(false, [1.3e100, 1.2e+100, 1.3e-10, 1.1, 1, 2])).toEqual(['1.3e-10', '1', '1.1', '2', '1.2e+100', '1.3e+100']);
});
it('should sort by float when autodetecting a mix of floats and integers are present', function(){
expect(sortedTable(false, [1.3, 1.2, 1.1, 1, 2])).toEqual(['1', '1.1', '1.2', '1.3', '2']);
});

0 comments on commit bf8b5de

Please sign in to comment.