# HG changeset patch # User Gregory Szorc # Date 1536704921 25200 # Node ID 8d8e61df82597fbe2a65e1a15442019107f852c7 # Parent 238a1480d7adb12367589c0233e93297c4d3bf22 narrowspec: validate patterns when loading and saving spec file Patterns should be normalized and validated before being passed into narrowspec.save(). Let's assert that by checking immediately before writing the narrow spec file. And let's assert that patterns loaded from the spec file also conform. Differential Revision: https://phab.mercurial-scm.org/D4524 diff -r 238a1480d7ad -r 8d8e61df8259 mercurial/narrowspec.py --- a/mercurial/narrowspec.py Mon Sep 10 22:34:19 2018 +0900 +++ b/mercurial/narrowspec.py Tue Sep 11 15:28:41 2018 -0700 @@ -164,9 +164,15 @@ if profiles: raise error.Abort(_("including other spec files using '%include' is not" " supported in narrowspec")) + + validatepatterns(includepats) + validatepatterns(excludepats) + return includepats, excludepats def save(repo, includepats, excludepats): + validatepatterns(includepats) + validatepatterns(excludepats) spec = format(includepats, excludepats) repo.svfs.write(FILENAME, spec) diff -r 238a1480d7ad -r 8d8e61df8259 tests/test-narrow-patterns.t --- a/tests/test-narrow-patterns.t Mon Sep 10 22:34:19 2018 +0900 +++ b/tests/test-narrow-patterns.t Tue Sep 11 15:28:41 2018 -0700 @@ -439,3 +439,31 @@ abort: invalid prefix on narrow pattern: set:ignored (narrow patterns must begin with one of the following: path:, rootfilesin:) [255] + + $ cat .hg/store/narrowspec + [include] + path:dir1 + path:dir1/dirA + [exclude] + + $ cat > .hg/store/narrowspec << EOF + > [include] + > glob:** + > EOF + + $ hg tracked + abort: invalid prefix on narrow pattern: glob:** + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255] + + $ cat > .hg/store/narrowspec << EOF + > [include] + > path:. + > [exclude] + > set:ignored + > EOF + + $ hg tracked + abort: invalid prefix on narrow pattern: set:ignored + (narrow patterns must begin with one of the following: path:, rootfilesin:) + [255]