Skip to content

Commit

Permalink
encoding/charmap: avoid error when rune is not supported
Browse files Browse the repository at this point in the history
Previously, using writer, if rune is not supported then error "encoding: rune not supported by encoding." is triggered.

This change avoid the error and doesn't write the unsupported character if new exported variable EmptyUnsupportedRune is true
xhit committed Apr 25, 2020
1 parent 2909f72 commit 1d7d35d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions encoding/charmap/charmap.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@ import (
// These encodings vary only in the way clients should interpret them. Their
// coded character set is identical and a single implementation can be shared.
var (
// EmptyUnsupportedRune is used for avoid "encoding: rune not supported by encoding." error and skip the character
EmptyUnsupportedRune bool

// ISO8859_6E is the ISO 8859-6E encoding.
ISO8859_6E encoding.Encoding = &iso8859_6E

@@ -203,6 +206,10 @@ loop:
// Binary search in [low, high) for that rune in the m.charmap.encode table.
for low, high := int(m.charmap.low), 0x100; ; {
if low >= high {
if EmptyUnsupportedRune {
nSrc += size
continue loop
}
err = internal.RepertoireError(m.charmap.replacement)
break loop
}

0 comments on commit 1d7d35d

Please sign in to comment.