Fix Windows EOLs in tables

v2-issue423-crlf
Vytautas Šaltenis 2018-08-18 22:57:50 +03:00
parent 63fc0561e7
commit abb2c4cc00
2 changed files with 23 additions and 2 deletions

View File

@ -755,6 +755,7 @@ func (p *Markdown) table(data []byte) int {
table.Unlink()
return 0
}
i, _ = skipWindowsNewline(i, data)
p.addBlock(TableBody, nil)
@ -772,6 +773,7 @@ func (p *Markdown) table(data []byte) int {
}
// include the newline in data sent to tableRow
i, _ = skipWindowsNewline(i, data)
if i < len(data) && iseol(data[i]) {
i++
}
@ -805,6 +807,7 @@ func (p *Markdown) tableHeader(data []byte) (size int, columns []CellAlignFlags)
}
// include the newline in the data sent to tableRow
i, _ = skipWindowsNewline(i, data)
j := i
if j < len(data) && iseol(data[j]) {
j++
@ -815,14 +818,15 @@ func (p *Markdown) tableHeader(data []byte) (size int, columns []CellAlignFlags)
if data[0] == '|' {
colCount--
}
if i > 2 && data[i-1] == '|' && !isBackslashEscaped(data, i-1) {
lastPipe := backupWindowsNewline(i, data)
if data[lastPipe] == '|' && !isBackslashEscaped(data, lastPipe) {
colCount--
}
columns = make([]CellAlignFlags, colCount)
// move on to the header underline
i++
i = j
if i >= len(data) {
return
}

View File

@ -14,6 +14,7 @@
package blackfriday
import (
"encoding/hex"
"strings"
"testing"
)
@ -1888,3 +1889,19 @@ func TestIsEmpty(t *testing.T) {
}
}
}
func TestRepro(t *testing.T) {
// XXX: this is a temporary test to ensure the tables fix works. It will
// later be OK to remove it because it will be covered by the usual tests,
// which will be dual-run with Unix and Windows EOLs.
s, err := hex.DecodeString("4e616d65202020207c204167650d0a2d2d2d2d2d2d2d2d7c2d2d2d2d2d2d0d0a426f6220202020207c2032370d0a416c6963652020207c203233")
if err != nil {
panic(err)
}
var tests = []string{
string(s),
"<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Age</th>\n</tr>\n</thead>\n\n" +
"<tbody>\n<tr>\n<td>Bob</td>\n<td>27</td>\n</tr>\n\n<tr>\n<td>Alice</td>\n<td>23</td>\n</tr>\n</tbody>\n</table>\n",
}
doTestsBlock(t, tests, Tables)
}