Skip to content

Commit

Permalink
Fix svg and xml wrong order
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vasile committed Mar 15, 2019
1 parent b41f473 commit 087445f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions matchers/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func Rtf(in []byte) bool {
return bytes.Equal(in[:6], []byte("\x7b\x5c\x72\x74\x66\x31"))
}

// SVG matches a SVG file.
func Svg(in []byte) bool {
return bytes.Contains(in, []byte("<svg"))
}
11 changes: 6 additions & 5 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var files = map[string]*Node{
"a.html": Html,
"a.xml": Xml,
"a.svg": Svg,
"a1.svg": Svg,
"a.txt": Txt,
"a.php": Php,
"a.ps": Ps,
Expand All @@ -78,7 +79,7 @@ var files = map[string]*Node{
}

func TestMatching(t *testing.T) {
errStr := "Mime: %s != DetectedMime: %s; err: %v"
errStr := "File: %s; Mime: %s != DetectedMime: %s; err: %v"
for fName, node := range files {
fileName := filepath.Join(testDataDir, fName)
f, err := os.Open(fileName)
Expand All @@ -91,20 +92,20 @@ func TestMatching(t *testing.T) {
}

if dMime, _ := Detect(data); dMime != node.Mime() {
t.Errorf(errStr, node.Mime(), dMime, nil)
t.Errorf(errStr, fName, node.Mime(), dMime, nil)
}

if _, err := f.Seek(io.SeekStart, 0); err != nil {
t.Errorf(errStr, node.Mime(), Root.Mime(), err)
t.Errorf(errStr, fName, node.Mime(), Root.Mime(), err)
}

if dMime, _, err := DetectReader(f); dMime != node.Mime() {
t.Errorf(errStr, node.Mime(), dMime, err)
t.Errorf(errStr, fName, node.Mime(), dMime, err)
}
f.Close()

if dMime, _, err := DetectFile(fileName); dMime != node.Mime() {
t.Errorf(errStr, node.Mime(), dMime, err)
t.Errorf(errStr, fName, node.Mime(), dMime, err)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions testdata/a1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var (
Ogg = NewNode("application/ogg", "ogg", matchers.Ogg)

Txt = NewNode("text/plain", "txt", matchers.Txt,
Html, Xml, Php, Js, Lua, Perl, Python, Json, Rtf, Tcl)
Html, Svg, Xml, Php, Js, Lua, Perl, Python, Json, Rtf, Tcl)
Xml = NewNode("text/xml; charset=utf-8", "xml", matchers.Xml,
Svg, X3d, Kml, Collada, Gml, Gpx)
X3d, Kml, Collada, Gml, Gpx)
Json = NewNode("application/json", "json", matchers.Json)
Html = NewNode("text/html; charset=utf-8", "html", matchers.Html)
Php = NewNode("text/x-php; charset=utf-8", "php", matchers.Php)
Expand Down

0 comments on commit 087445f

Please sign in to comment.