Browse Source

Fix versioner regexp's (fixes #1023)

Audrius Butkevicius 11 years ago
parent
commit
c1069052ae
2 changed files with 5 additions and 1 deletions
  1. 1 1
      internal/versioner/util.go
  2. 4 0
      internal/versioner/versioner_test.go

+ 1 - 1
internal/versioner/util.go

@@ -28,7 +28,7 @@ func taggedFilename(name, tag string) string {
 	return filepath.Join(dir, withoutExt+"~"+tag+ext)
 	return filepath.Join(dir, withoutExt+"~"+tag+ext)
 }
 }
 
 
-var tagExp = regexp.MustCompile(`~([^~.]+)(?:\.[^.]+)?$`)
+var tagExp = regexp.MustCompile(`.*~([^~.]+)(?:\.[^.]+)?$`)
 
 
 // Returns the tag from a filename, whether at the end or middle.
 // Returns the tag from a filename, whether at the end or middle.
 func filenameTag(path string) string {
 func filenameTag(path string) string {

+ 4 - 0
internal/versioner/versioner_test.go

@@ -25,10 +25,14 @@ func TestTaggedFilename(t *testing.T) {
 		{filepath.Join("foo", "bar.baz"), "tag", filepath.Join("foo", "bar~tag.baz")},
 		{filepath.Join("foo", "bar.baz"), "tag", filepath.Join("foo", "bar~tag.baz")},
 		{"bar.baz", "tag", "bar~tag.baz"},
 		{"bar.baz", "tag", "bar~tag.baz"},
 		{"bar", "tag", "bar~tag"},
 		{"bar", "tag", "bar~tag"},
+		{"~$ufheft2.docx", "20140612-200554", "~$ufheft2~20140612-200554.docx"},
+		{"alle~4.mgz", "20141106-094415", "alle~4~20141106-094415.mgz"},
 
 
 		// Parsing test only
 		// Parsing test only
 		{"", "tag-only", "foo/bar.baz~tag-only"},
 		{"", "tag-only", "foo/bar.baz~tag-only"},
 		{"", "tag-only", "bar.baz~tag-only"},
 		{"", "tag-only", "bar.baz~tag-only"},
+		{"", "20140612-200554", "~$ufheft2.docx~20140612-200554"},
+		{"", "20141106-094415", "alle~4.mgz~20141106-094415"},
 	}
 	}
 
 
 	for _, tc := range cases {
 	for _, tc := range cases {