xmlroundtrip

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: BSD-2-Clause Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xmlroundtrip rejects XML documents that encoding/xml would change if it decoded and re-encoded them.

Go's encoding/xml does not round-trip some namespace prefixes on elements and attributes, or some directives, unchanged (CVE-2020-29509, CVE-2020-29510, CVE-2020-29511). This package rejects any document with a token that is not stable under such a round trip. It makes the same check as github.com/mattermost/xml-roundtrip-validator, but without allocating a new encoder and decoder for every token, so the memory it allocates is a small multiple of the size of its input.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(data []byte) error

Validate returns an error if any token of data does not survive a round trip through encoding/xml unchanged. It does not check that data is well-formed beyond what encoding/xml's tokenizer requires.

Types

type Error

type Error struct {
	// Line and Column give the position (1-based) of the start of the token.
	Line, Column int64
	Err          error
}

Error reports the token of a document that does not survive a round trip, or that could not be checked.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type RoundTripError

type RoundTripError struct {
	Expected, Observed xml.Token
}

RoundTripError reports a token that encoding/xml decodes differently after encoding it.

func (*RoundTripError) Error

func (e *RoundTripError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL