From b2509005abb59358abbdcf9ce379b221fff60f04 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Fri, 20 Jun 2014 08:49:58 +0100 Subject: [PATCH] Fix: Percentage columns detected as date columns in Chrome * V8 strips unknown characters not only at the start of a string given to Date.parse() but also at the end. So `10%` (for example) was being detected as a date type. * This fixes DataTables/DataTables #354 --- .datatables-commit-sync | 2 +- media/js/jquery.dataTables.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index e78de161..2c2466cc 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -82b2580b26e160220f92abfa51c7cbca2b53b17a +0e5a4d7a663a0a88e12b47d08883a381fca7d1e2 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 6e47a9ad..b24d3a39 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -105,7 +105,8 @@ var _re_dic = {}; var _re_new_lines = /[\r\n]/g; var _re_html = /<.*?>/g; - var _re_date_start = /^[\d\+\-a-zA-Z]/; + var _re_date_start = /^[\w\+\-]/; + var _re_date_end = /[\w\+\-]$/; // Escape regular expression special characters var _re_escape_regex = new RegExp( '(\\' + [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ].join('|\\') + ')', 'g' ); @@ -13980,10 +13981,10 @@ // Dates (only those recognised by the browser's Date.parse) function ( d, settings ) { - // V8 will remove any unknown characters at the start of the expression, - // leading to false matches such as `$245.12` being a valid date. See - // forum thread 18941 for detail. - if ( d && ! _re_date_start.test(d) ) { + // V8 will remove any unknown characters at the start and end of the + // expression, leading to false matches such as `$245.12` or `10%` being + // a valid date. See forum thread 18941 for detail. + if ( d && ( ! _re_date_start.test(d) || ! _re_date_end.test(d) ) ) { return null; } var parsed = Date.parse(d);