github.com/google/osv-scalibr@v0.4.1/enricher/govulncheck/source/internal/url/url_other_test.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Derived from https://github.com/golang/go/blob/7c2b69080a0b9e35174cc9c93497b6e7176f8275/src/cmd/go/internal/web/url.go 16 // TODO(golang.org/issue/32456): If accepted, move these functions into the 17 // net/url package. 18 // 19 // Copyright 2023 The Go Authors. All rights reserved. 20 // Use of this source code is governed by a BSD-style 21 // license that can be found in the LICENSE file. 22 23 //go:build !windows 24 25 package url_test 26 27 // Code copied from https://github.com/golang/go/blob/7c2b69080a0b9e35174cc9c93497b6e7176f8275/src/cmd/go/internal/web/url_other_test.go 28 29 var urlTests = []struct { 30 url string 31 filePath string 32 canonicalURL string // If empty, assume equal to url. 33 wantErr string 34 }{ 35 // Examples from RFC 8089: 36 { 37 url: `file:///path/to/file`, 38 filePath: `/path/to/file`, 39 }, 40 { 41 url: `file:/path/to/file`, 42 filePath: `/path/to/file`, 43 canonicalURL: `file:///path/to/file`, 44 }, 45 { 46 url: `file://localhost/path/to/file`, 47 filePath: `/path/to/file`, 48 canonicalURL: `file:///path/to/file`, 49 }, 50 51 // We reject non-local files. 52 { 53 url: `file://host.example.com/path/to/file`, 54 wantErr: "file URL specifies non-local host", 55 }, 56 }