Commit 4e9bf1b2 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'fj-fix-svg-detection' into 'master'

Fix SVG recognition to get the proper content type

See merge request gitlab-org/gitlab-workhorse!353
parents c718f889 39dd7332
......@@ -5,7 +5,7 @@ import (
"net/http"
"regexp"
svg "github.com/h2non/go-is-svg"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/utils/svg"
)
var (
......
......@@ -73,6 +73,12 @@ func TestSetProperContentTypeAndDisposition(t *testing.T) {
contentDisposition: "attachment",
body: testhelper.LoadFile(t, "testdata/image.svg"),
},
{
desc: "Partial SVG type",
contentType: "image/svg+xml",
contentDisposition: "attachment",
body: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 330 82\"><title>SVG logo combined with the W3C logo, set horizontally</title><desc>The logo combines three entities displayed horizontall</desc><metadata>",
},
{
desc: "Application type",
contentType: "application/pdf",
......
# go-is-svg [![Build Status](https://travis-ci.org/h2non/go-is-svg.png)](https://travis-ci.org/h2non/go-is-svg) [![GoDoc](https://godoc.org/github.com/h2non/go-is-svg?status.svg)](https://godoc.org/github.com/h2non/go-is-svg) [![Coverage Status](https://coveralls.io/repos/github/h2non/go-is-svg/badge.svg?branch=master)](https://coveralls.io/github/h2non/go-is-svg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/h2non/go-is-svg)](https://goreportcard.com/report/github.com/h2non/go-is-svg)
# go-is-svg
Tiny package to verify if a given file buffer is an SVG image in Go (golang).
See also [filetype](https://github.com/h2non/filetype) package for binary files type inference.
## Installation
```bash
......
package issvg
// Copyright (c) 2016 Tomas Aparicio. All rights reserved.
//
// Use of this source code is governed by a MIT License
// license that can be found in the LICENSE file or at
// https://github.com/h2non/go-is-svg/blob/master/LICENSE.
package svg
import (
"regexp"
......@@ -6,8 +12,8 @@ import (
)
var (
htmlCommentRegex = regexp.MustCompile("(?i)<!--([\\s\\S]*?)-->")
svgRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>[^*]*<\/svg>\s*$`)
htmlCommentRegex = regexp.MustCompile(`(?i)<!--([\s\S]*?)-->`)
svgRegex = regexp.MustCompile(`(?i)^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*>\s*)?<svg[^>]*>`)
)
// isBinary checks if the given buffer is a binary file.
......
......@@ -203,12 +203,6 @@
"version": "v1",
"versionExact": "v1.2.0"
},
{
"checksumSHA1": "v52fmR2hxX7o6emMN/dflEqys64=",
"path": "github.com/h2non/go-is-svg",
"revision": "35e8c4b0612ce1ab2a228e25a323b22482db6788",
"revisionTime": "2016-09-27T21:24:52Z"
},
{
"checksumSHA1": "mb0MqzDyYEQMgh8+qwVm1RV4cxc=",
"path": "github.com/jfbus/httprs",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment