From ec916bc1b394802b80db0414a17ae7dc20011dd1 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Mon, 10 Oct 2022 15:47:23 -0700 Subject: [PATCH] Test ensuring shortrefs are unique for edgecase (#1105) ## Description Some paths can generate identical unescaped strings even though they have different elements. Add a test ensuring they generate unique ShortRefs even under these conditions. ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * closes #1092 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/pkg/path/path_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pkg/path/path_test.go b/src/pkg/path/path_test.go index d90715e7b..05f491e7f 100644 --- a/src/pkg/path/path_test.go +++ b/src/pkg/path/path_test.go @@ -414,6 +414,18 @@ func (suite *PathUnitSuite) TestShortRefIsUnique() { assert.NotEqual(suite.T(), pb1.ShortRef(), pb2.ShortRef()) } +// TestShortRefUniqueWithEscaping tests that two paths that output the same +// unescaped string but different escaped strings have different shortrefs. This +// situation can occur when one path has embedded path separators while the +// other does not but contains the same characters. +func (suite *PathUnitSuite) TestShortRefUniqueWithEscaping() { + pb1 := Builder{}.Append(`this`, `is`, `a`, `path`) + pb2 := Builder{}.Append(`this`, `is/a`, `path`) + + require.NotEqual(suite.T(), pb1, pb2) + assert.NotEqual(suite.T(), pb1.ShortRef(), pb2.ShortRef()) +} + func (suite *PathUnitSuite) TestFromStringErrors() { table := []struct { name string