From 96035d255bf92c85ffe1e60daf4ef70ef6c4568c Mon Sep 17 00:00:00 2001 From: Kasper Nilsson Date: Mon, 12 Sep 2016 14:53:33 -0700 Subject: [PATCH] Enhance special filename sorting Previously, filenames were directly locale compared, which caused some instances of sorting to occur incorrectly (e.g. sorting task.go after task_test.go). The new behavior is to compare the filenames first, and then compare the filename with extension iff the filenames are equal. Bug: Issue 4545 Change-Id: I9fe5a5b111c8ae9b4dc587b97753aa6aa11224ef --- .../app/elements/core/gr-search-bar/gr-search-bar.js | 2 +- .../gr-rest-api-interface/gr-rest-api-interface.js | 3 +-- .../gr-rest-api-interface_test.html | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js index 6de7dfdb89..d8121b71dc 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js @@ -139,8 +139,8 @@ } else { target.blur(); } - // @see Issue 4255. if (this._inputVal) { + // @see Issue 4255. page.show('/q/' + encodeURIComponent(encodeURIComponent(this._inputVal))); } diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 19a405c9de..632ba06ee0 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -442,8 +442,7 @@ return 1; } } - - return a.localeCompare(b); + return aFile.localeCompare(bFile) || a.localeCompare(b); }, getChangeRevisionActions: function(changeNum, patchNum) { diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html index 2481b1f27c..8f994f0f66 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface_test.html @@ -252,6 +252,17 @@ limitations under the License. 'minidump/minidump_thread_writer.h', 'minidump/minidump_thread_writer.cc', ]); + + // Regression test for Issue 4545. + assert.deepEqual([ + 'task_test.go', + 'task.go', + ] + .sort(element._specialFilePathCompare), + [ + 'task.go', + 'task_test.go', + ]); }); test('rebase always enabled', function(done) {