Fixed sort algo for additional cases

remotes/origin/fix-10825
Vincent Petry 12 years ago
parent 173059f6d0
commit f2001a48a4
  1. 4
      core/js/js.js
  2. 6
      core/js/tests/specs/coreSpec.js
  3. 3
      lib/private/naturalsort.php
  4. 4
      tests/lib/naturalsort.php

@ -1373,7 +1373,8 @@ OC.Util = {
while (x < t.length) {
c = t.charAt(x);
var m = (c === '.' || (c >= '0' && c <= '9'));
// only include the dot in strings
var m = ((!n && c === '.') || (c >= '0' && c <= '9'));
if (m !== n) {
// next chunk
y++;
@ -1393,6 +1394,7 @@ OC.Util = {
* or 0 if the strings are identical
*/
naturalSortCompare: function(a, b) {
var x;
var aa = OC.Util._chunkify(a);
var bb = OC.Util._chunkify(b);

@ -531,10 +531,14 @@ describe('Core base tests', function() {
'za',
'ghi 1.txt',
'ghi 12.txt',
'zz'
'zz',
'15.txt',
'15b.txt'
];
a.sort(OC.Util.naturalSortCompare);
expect(a).toEqual([
'15.txt',
'15b.txt',
'123.txt',
'124.txt',
'abc',

@ -39,7 +39,8 @@ class NaturalSort {
while ($x < $length) {
$c = $t[$x];
$m = ($c === '.' || ($c >= '0' && $c <= '9'));
// only include the dot in strings
$m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9'));
if ($m !== $n) {
// next chunk
$y++;

@ -74,9 +74,13 @@ class Test_NaturalSort extends PHPUnit_Framework_TestCase {
'ghi 1.txt',
'ghi 12.txt',
'zz',
'15.txt',
'15b.txt',
),
// sorted
array(
'15.txt',
'15b.txt',
'123.txt',
'124.txt',
'abc',

Loading…
Cancel
Save