]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed sort algo for additional cases
authorVincent Petry <pvince81@owncloud.com>
Wed, 23 Jul 2014 10:52:13 +0000 (12:52 +0200)
committerVincent Petry <pvince81@owncloud.com>
Mon, 11 Aug 2014 11:28:53 +0000 (13:28 +0200)
core/js/js.js
core/js/tests/specs/coreSpec.js
lib/private/naturalsort.php
tests/lib/naturalsort.php

index b6bfa01d0d52b019227c44d7f9ab6dd3dfb45c61..60791dcc8d8b2dbfac87c9dcbecbc6ced6a98e7d 100644 (file)
@@ -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);
 
index 265b9deac39353d11a376569c2b20a653f7cd6a3..6d40a066de8dfb4b51ff6ecebab907c3272d0574 100644 (file)
@@ -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',
index b6fa0ed89684d1cc7ecf5e89888d881847e52eab..e10ce8e45e72fa97bbaa7853b157e83a58df6ef4 100644 (file)
@@ -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++;
index a880acaeec425268f67042f264559aa9bfb4ddfa..09a0e6a5f9d7454555917a9b8b57358399e197ac 100644 (file)
@@ -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',