Update dependencies

This commit is contained in:
Ken-Håvard Lieng 2019-06-09 02:01:48 +02:00
parent 7ad76273c0
commit 540efa03c4
485 changed files with 57821 additions and 12429 deletions

View file

@ -2,4 +2,5 @@ language: go
before_install:
- go get github.com/mattn/goveralls
script:
- goveralls -v -service travis-ci -repotoken $COVERALLS_TOKEN || go test -v ./...
- go test -v -covermode=count -coverprofile=profile.cov . ./buffer ./css ./html ./js ./json ./strconv ./svg ./xml
- goveralls -v -coverprofile=profile.cov -service travis-ci -repotoken $COVERALLS_TOKEN

View file

@ -1,5 +1,11 @@
# Parse [![Build Status](https://travis-ci.org/tdewolff/parse.svg?branch=master)](https://travis-ci.org/tdewolff/parse) [![GoDoc](http://godoc.org/github.com/tdewolff/parse?status.svg)](http://godoc.org/github.com/tdewolff/parse) [![Coverage Status](https://coveralls.io/repos/github/tdewolff/parse/badge.svg?branch=master)](https://coveralls.io/github/tdewolff/parse?branch=master)
***BE AWARE: YOU NEED GO 1.9.7+, 1.10.3+, 1.11 to run the latest release!!!***
If you cannot upgrade Go, please pin to **parse@v2.3.4**
---
This package contains several lexers and parsers written in [Go][1]. All subpackages are built to be streaming, high performance and to be in accordance with the official (latest) specifications.
The lexers are implemented using `buffer.Lexer` in https://github.com/tdewolff/parse/buffer and the parsers work on top of the lexers. Some subpackages have hashes defined (using [Hasher](https://github.com/tdewolff/hasher)) that speed up common byte-slice comparisons.

View file

@ -154,5 +154,5 @@ func (z *Lexer) Offset() int {
// Bytes returns the underlying buffer.
func (z *Lexer) Bytes() []byte {
return z.buf
return z.buf[:len(z.buf)-1]
}

View file

@ -26,7 +26,7 @@ func NewError(msg string, r io.Reader, offset int) *Error {
}
}
// NewErrorLexer creates a new error from a *buffer.Lexer
// NewErrorLexer creates a new error from an active Lexer.
func NewErrorLexer(msg string, l *buffer.Lexer) *Error {
r := buffer.NewReader(l.Bytes())
offset := l.Offset()
@ -37,7 +37,7 @@ func NewErrorLexer(msg string, l *buffer.Lexer) *Error {
// Context is the entire line at which the error occurred.
func (e *Error) Position() (int, int, string) {
if e.line == 0 {
e.line, e.column, e.context, _ = Position(e.r, e.Offset)
e.line, e.column, e.context = Position(e.r, e.Offset)
}
return e.line, e.column, e.context
}

View file

@ -1,11 +1,11 @@
# HTML [![GoDoc](http://godoc.org/github.com/tdewolff/parse/html?status.svg)](http://godoc.org/github.com/tdewolff/parse/html) [![GoCover](http://gocover.io/_badge/github.com/tdewolff/parse/html)](http://gocover.io/github.com/tdewolff/parse/html)
# HTML [![GoDoc](http://godoc.org/github.com/tdewolff/parse/html?status.svg)](http://godoc.org/github.com/tdewolff/parse/html)
This package is an HTML5 lexer written in [Go][1]. It follows the specification at [The HTML syntax](http://www.w3.org/TR/html5/syntax.html). The lexer takes an io.Reader and converts it into tokens until the EOF.
## Installation
Run the following command
go get github.com/tdewolff/parse/html
go get -u github.com/tdewolff/parse/v2/html
or add the following import and run project with `go get`

File diff suppressed because it is too large Load diff

View file

@ -52,7 +52,7 @@ var charTable = [256]bool{
}
// EscapeAttrVal returns the escaped attribute value bytes without quotes.
func EscapeAttrVal(buf *[]byte, orig, b []byte) []byte {
func EscapeAttrVal(buf *[]byte, orig, b []byte, isXML bool) []byte {
singles := 0
doubles := 0
unquoted := true
@ -80,7 +80,7 @@ func EscapeAttrVal(buf *[]byte, orig, b []byte) []byte {
}
}
}
if unquoted {
if unquoted && !isXML {
return b
} else if !entities && len(orig) == len(b)+2 && (singles == 0 && orig[0] == '\'' || doubles == 0 && orig[0] == '"') {
return orig
@ -89,14 +89,14 @@ func EscapeAttrVal(buf *[]byte, orig, b []byte) []byte {
n := len(b) + 2
var quote byte
var escapedQuote []byte
if doubles > singles {
n += singles * 4
quote = '\''
escapedQuote = singleQuoteEntityBytes
} else {
if singles >= doubles || isXML {
n += doubles * 4
quote = '"'
escapedQuote = doubleQuoteEntityBytes
} else {
n += singles * 4
quote = '\''
escapedQuote = singleQuoteEntityBytes
}
if n > cap(*buf) {
*buf = make([]byte, 0, n) // maximum size, not actual size

View file

@ -10,48 +10,45 @@ import (
// Position returns the line and column number for a certain position in a file. It is useful for recovering the position in a file that caused an error.
// It only treates \n, \r, and \r\n as newlines, which might be different from some languages also recognizing \f, \u2028, and \u2029 to be newlines.
func Position(r io.Reader, offset int) (line, col int, context string, err error) {
func Position(r io.Reader, offset int) (line, col int, context string) {
l := buffer.NewLexer(r)
line = 1
for {
c := l.Peek(0)
if c == 0 {
col = l.Pos() + 1
context = positionContext(l, line, col)
err = l.Err()
if err == nil {
err = io.EOF
}
return
}
if offset == l.Pos() {
if c == 0 && l.Err() != nil || offset == l.Pos() {
col = l.Pos() + 1
context = positionContext(l, line, col)
return
}
nNewline := 0
if c == '\n' {
l.Move(1)
line++
offset -= l.Pos()
l.Skip()
nNewline = 1
} else if c == '\r' {
if l.Peek(1) == '\n' {
if offset == l.Pos()+1 {
l.Move(1)
continue
}
l.Move(2)
nNewline = 2
} else {
l.Move(1)
nNewline = 1
}
} else if c >= 0xC0 {
if r, n := l.PeekRune(0); r == '\u2028' || r == '\u2029' {
nNewline = n
}
} else {
l.Move(1)
}
if nNewline > 0 {
if offset < l.Pos()+nNewline {
// move onto offset position, let next iteration handle it
l.Move(offset - l.Pos())
continue
}
l.Move(nNewline)
line++
offset -= l.Pos()
l.Skip()
} else {
l.Move(1)
}
}
}
@ -65,15 +62,36 @@ func positionContext(l *buffer.Lexer, line, col int) (context string) {
l.Move(1)
}
// replace unprintable characters by a space
// cut off front or rear of context to stay between 60 characters
b := l.Lexeme()
limit := 60
offset := 20
ellipsisFront := ""
ellipsisRear := ""
if limit < len(b) {
if col <= limit-offset {
ellipsisRear = "..."
b = b[:limit-3]
} else if col >= len(b)-offset-3 {
ellipsisFront = "..."
col -= len(b) - offset - offset - 7
b = b[len(b)-offset-offset-4:]
} else {
ellipsisFront = "..."
ellipsisRear = "..."
b = b[col-offset-1 : col+offset]
col = offset + 4
}
}
// replace unprintable characters by a space
for i, c := range b {
if c < 0x20 || c == 0x7F {
b[i] = ' '
}
}
context += fmt.Sprintf("%5d: %s\n", line, string(b))
context += fmt.Sprintf("%5d: %s%s%s\n", line, ellipsisFront, string(b), ellipsisRear)
context += fmt.Sprintf("%s^", strings.Repeat(" ", col+6))
return
}

View file

@ -23,7 +23,8 @@ func EqualFold(s, targetLower []byte) bool {
return false
}
for i, c := range targetLower {
if s[i] != c && (c < 'A' && c > 'Z' || s[i]+('a'-'A') != c) {
d := s[i]
if d != c && (d < 'A' || d > 'Z' || d+('a'-'A') != c) {
return false
}
}