File: remove-go4.org-dependency.patch

package info (click to toggle)
golang-github-opencontainers-image-spec 1.0.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, bullseye-backports, bullseye-updates
  • size: 632 kB
  • sloc: makefile: 119
file content (60 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 3053e589507dee74f61ae854f33451e3c8d47f15 Mon Sep 17 00:00:00 2001
From: Shengjing Zhu <zhsj@debian.org>
Date: Mon, 23 Mar 2020 18:35:56 +0800
Subject: [PATCH] Remove go4.org dependency

The offset to line/col translation is easy to implement. Not worthy
to bring a third-party dependency.

PS. I think this code is never used, but removing it is too aggressive
since it exposes public api.

Signed-off-by: Shengjing Zhu <zhsj@debian.org>

Forwarded: https://github.com/opencontainers/image-spec/pull/800
---
 schema/error.go | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/schema/error.go b/schema/error.go
index 8b0bfc2..867e2b1 100644
--- a/schema/error.go
+++ b/schema/error.go
@@ -15,10 +15,9 @@
 package schema
 
 import (
+	"bufio"
 	"encoding/json"
 	"io"
-
-	"go4.org/errorutil"
 )
 
 // A SyntaxError is a description of a JSON syntax error
@@ -36,7 +35,21 @@ func (e *SyntaxError) Error() string { return e.msg }
 // If the given error is not a *json.SyntaxError it is returned unchanged.
 func WrapSyntaxError(r io.Reader, err error) error {
 	if serr, ok := err.(*json.SyntaxError); ok {
-		line, col, _ := errorutil.HighlightBytePosition(r, serr.Offset)
+		buf := bufio.NewReader(r)
+		line := 1
+		col := 0
+		for i := int64(0); i < serr.Offset; i++ {
+			b, berr := buf.ReadByte()
+			if berr != nil {
+				break
+			}
+			if b == '\n' {
+				line++
+				col = 1
+			} else {
+				col++
+			}
+		}
 		return &SyntaxError{serr.Error(), line, col, serr.Offset}
 	}
 
-- 
2.29.2