aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/xml/xml.go
AgeCommit message (Collapse)Author
2024-09-04encoding/xml: allow ]]> in attribute valuesDemi Marie Obenour
This is permitted by the XML specification. Fixes #68387 Change-Id: Ic4ab5520a08a5a997f1c3d13c6d5f80c0521e45c GitHub-Last-Rev: 6d2ac307bbd0ba7d50830ad8b879c00cc3a7242b GitHub-Pull-Request: golang/go#69197 Reviewed-on: https://go-review.googlesource.com/c/go/+/610056 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-08Revert "encoding/xml: reject XML declaration after start of document"Russ Cox
This reverts commit 8a0fbd75a54c27ff2ae624ac2775bf752cdbceb4. Reason for revert: Breaking real-world tests inside Google, which means it probably breaks real-world tests outside Google. One instance I have seen is a <!-- --> comment (often a copyright notice) before the procinst. Another test checks that a canonicalizer can handle a test input that simply has procinsts mid-XML. XML is full of contradictions, XML implementations more so. If we are going to start being picky, that probably needs to be controlled by a GODEBUG (and a proposal). For #65691 (will reopen manually). Change-Id: Ib52d0944b1478e71744a2a35b271fdf7e1c972ca Reviewed-on: https://go-review.googlesource.com/c/go/+/570175 Reviewed-by: Than McIntosh <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org>
2024-02-28encoding/xml: display closing space in error messageConstantin Konstantinidis
Fixes #48890 Change-Id: I7644d091ad92663bda52ef4905239ec499ef9207 Reviewed-on: https://go-review.googlesource.com/c/go/+/535535 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2024-02-22encoding/xml: reject XML declaration after start of documentAxel Wagner
The XML specification requires an XML declaration, if present, to only appear at the very beginning of the document, not even preceded by whitespace. The parser currently accepts it at any part of the input. Rejecting whitespace at the beginning of the file might break too many users. This change instead only rejects an XML declaration preceded by a non-whitespace token *and* allows the Encoder to emit whitespace before an XML declaration. This means that a token stream produced by the Decoder can be passed to the Encoder without error, while we still don't emit clearly invalid XML. This might break programs depending on Decoder allowing arbitrary XML before the XML declaration. Fixes #65691. Change-Id: Ib1d4b3116aee63f40fd377f90595780b4befd1ee Reviewed-on: https://go-review.googlesource.com/c/go/+/564035 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-08encoding/xml: rewrite func procInstJes Cok
This CL tries to make function procInst more exact, also adds test cases, however, including tricky ones. Change-Id: If421299fc84d136e56a25dba7a4919c4424702c8 GitHub-Last-Rev: b9a3192718ae5535d66fddd260c27b48d93b4af1 GitHub-Pull-Request: golang/go#64336 Reviewed-on: https://go-review.googlesource.com/c/go/+/544475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-08encoding: modernize Go documentationJoe Tsai
Across all encoding packages, linkify declarations if possible. In some cases, we convert a code block into a bulleted list, which then further allows for more linkification. Change-Id: I68fedf362615b34228bab5d4859b7d87d831c570 Reviewed-on: https://go-review.googlesource.com/c/go/+/524977 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-05-17encoding/xml: wrap charsetReader errorsThuy Linh Luu
This change wraps the errors from the CharsetReader function so the caller can distinguish different error conditions. Context: I have an XML file with an unknown encoding which I like to handle separately. I like to use the CharsetReader for this but the error type has not been forwarded. Change-Id: I6739a0dee04ec376cd20536be2806ce7f50c5213 GitHub-Last-Rev: ada9dd510f9a5b7f8c9473f6864077e0ed6898bd GitHub-Pull-Request: golang/go#60199 Reviewed-on: https://go-review.googlesource.com/c/go/+/494897 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-11-29Revert "encoding/xml: disallow empty namespace when prefix is set"Ian Lance Taylor
This reverts CL 105636. Reason for revert: Fails with existing XML data. At this stage in the release cycle we should revert, and try again next time with some way to support existing XML. For #8068 Change-Id: Ia84cbf3a84878ac7190f72998545dee22c36c45e Reviewed-on: https://go-review.googlesource.com/c/go/+/453996 Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-11-09encoding/xml: error when more than one colon in qualified namesConstantin Konstantinidis
Add test. Fixes #20396 Change-Id: I89e9013eb338f831e1908e390b284794df78fb6b Reviewed-on: https://go-review.googlesource.com/c/go/+/103875 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-11-09encoding/xml: disallow empty namespace when prefix is setConstantin Konstantinidis
Non-regression tests are added. Fixes #8068 Change-Id: Icb36c910bbf4955743b7aa8382002b2d9246fadc Reviewed-on: https://go-review.googlesource.com/c/go/+/105636 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-11-09encoding/xml: error when closing tag does not match opening tagConstantin Konstantinidis
Comparing opening and closing tag is done using the prefix when available. Documentation states that Token returns URI in the Space part of the Name. Translation has been moved for the End tag before the namespace is removed from the stack. After closing a tag using a namespace, the valid namespace must be taken from the opening tag. Tests added. Fixes #20685 Change-Id: I4d90b19f7e21a76663f0ea1c1db6c6bf9fd2a389 Reviewed-on: https://go-review.googlesource.com/c/go/+/107255 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-28encoding/xml: use bytes.Clonecuiweixie
Change-Id: I3218b1e3f8869f579facddb29471df13c835dc66 Reviewed-on: https://go-review.googlesource.com/c/go/+/435281 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
2022-08-09encoding/xml: use bytes.Buffer.WriteStringDaniel Martí
Change-Id: Icb0b917c48252ed8831e6c07109c1bc2d2438a42 Reviewed-on: https://go-review.googlesource.com/c/go/+/421234 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: hopehook <hopehook@qq.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Dan Kortschak <dan@kortschak.io>
2022-05-17all: fix spellingJohn Bampton
Change-Id: I68538a50c22b02cdb5aa2a889f9440fed7b94c54 GitHub-Last-Rev: aaac9e78340ac482e9cd1b506a035f271c29648c GitHub-Pull-Request: golang/go#52944 Reviewed-on: https://go-review.googlesource.com/c/go/+/406835 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2022-03-27encoding/xml: expose decoder line and columnPatrick Gundlach
The existing implementation of the xml decoder uses the line number only for reporting syntax errors. The line number of the last read token and the column within the line is useful for the users even in non-error conditions. Fixes #45628 Change-Id: I37b5033ff5ff8411793d8f5180f96aa4537e83f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/311270 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2022-03-04encoding/xml: improve the test coverage, fix minor bugsIskander Sharipov
Improve the test coverage of encoding/xml package by adding the test cases for the execution paths that were not covered before. Since it reveals a couple of issues, fix them as well while we're at it. As I used an `strings.EqualFold` instead of adding one more `strings.ToLower`, our fix to `autoClose()` tends to run faster as well as a result. name old time/op new time/op delta HTMLAutoClose-8 5.93µs ± 2% 5.75µs ± 3% -3.16% (p=0.000 n=10+10) name old alloc/op new alloc/op delta HTMLAutoClose-8 2.60kB ± 0% 2.58kB ± 0% -0.46% (p=0.000 n=10+10) name old allocs/op new allocs/op delta HTMLAutoClose-8 72.0 ± 0% 67.0 ± 0% -6.94% (p=0.000 n=10+10) The overall `encoding/xml` test coverage increase is `88.1% -> 89.9%`; although it may look insignificant, this CL covers some important corner cases, like `autoClose()` functionality (that was not tested at all). Fixes #49635 Fixes #49636 Change-Id: I50b2769896c197eb285672313b7148f4fe8bdb38 Reviewed-on: https://go-review.googlesource.com/c/go/+/364734 Trust: Bryan Mills <bcmills@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-15encoding/xml: replace comments inside directives with a spaceFilippo Valsorda
A Directive (like <!ENTITY xxx []>) can't have other nodes nested inside it (in our data structure representation), so there is no way to preserve comments. The previous behavior was to just elide them, which however might change the semantic meaning of the surrounding markup. Instead, replace them with a space which hopefully has the same semantic effect of the comment. Directives are not actually a node type in the XML spec, which instead specifies each of them separately (<!ENTITY, <!DOCTYPE, etc.), each with its own grammar. The rules for where and when the comments are allowed are not straightforward, and can't be implemented without implementing custom logic for each of the directives. Simply preserving the comments in the body of the directive would be problematic, as there can be unmatched quotes inside the comment. Whether those quotes are considered meaningful semantically or not, other parsers might disagree and interpret the output differently. This issue was reported by Juho Nurminen of Mattermost as it leads to round-trip mismatches. See #43168. It's not being fixed in a security release because round-trip stability is not a currently supported security property of encoding/xml, and we don't believe these fixes would be sufficient to reliably guarantee it in the future. Fixes CVE-2020-29510 Updates #43168 Change-Id: Icd86c75beff3e1e0689543efebdad10ed5178ce3 Reviewed-on: https://go-review.googlesource.com/c/go/+/277893 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2021-03-15encoding/xml: handle leading, trailing, or double colons in namesFilippo Valsorda
Before this change, <:name> would parse as <name>, which could cause issues in applications that rely on the parse-encode cycle to round-trip. Similarly, <x name:=""> would parse as expected but then have the attribute dropped when serializing because its name was empty. Finally, <a:b:c> would parse and get serialized incorrectly. All these values are invalid XML, but to minimize the impact of this change, we parse them whole into Name.Local. This issue was reported by Juho Nurminen of Mattermost as it leads to round-trip mismatches. See #43168. It's not being fixed in a security release because round-trip stability is not a currently supported security property of encoding/xml, and we don't believe these fixes would be sufficient to reliably guarantee it in the future. Fixes CVE-2020-29509 Fixes CVE-2020-29511 Updates #43168 Change-Id: I68321c4d867305046f664347192948a889af3c7f Reviewed-on: https://go-review.googlesource.com/c/go/+/277892 Run-TryBot: Filippo Valsorda <filippo@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Filippo Valsorda <filippo@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
2021-03-13all: use HTML5 br tagsJohn Bampton
In HTML5 br tags don't need a closing slash Change-Id: Ic53c43faee08c5b1267daa9a02cc186b1c255ca1 GitHub-Last-Rev: 652208116944d01b23b8af8f1af485da5e916d32 GitHub-Pull-Request: golang/go#44283 Reviewed-on: https://go-review.googlesource.com/c/go/+/292370 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-10encoding/xml: prevent infinite loop while decodingKatie Hockman
This change properly handles a TokenReader which returns an EOF in the middle of an open XML element. Thanks to Sam Whited for reporting this. Fixes CVE-2021-27918 Fixes #44913 Change-Id: Id02a3f3def4a1b415fa2d9a8e3b373eb6cb0f433 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1004594 Reviewed-by: Russ Cox <rsc@google.com> Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-by: Filippo Valsorda <valsorda@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/300391 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Alexander Rakoczy <alex@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-02-26all: avoid string(i) where i has type intIan Lance Taylor
Instead use string(r) where r has type rune. This is in preparation for a vet warning for string(i). Updates #32479 Change-Id: Ic205269bba1bd41723950219ecfb67ce17a7aa79 Reviewed-on: https://go-review.googlesource.com/c/go/+/220844 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Akhil Indurti <aindurti@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Toshihiro Shiino <shiino.toshihiro@gmail.com>
2019-10-30encoding/xml: fix token decoder on early EOFSam Whited
The documentation for TokenReader suggests that implementations of the interface may return a token and io.EOF together, indicating that it is the last token in the stream. This is similar to io.Reader. However, if you wrap such a TokenReader in a Decoder it complained about the EOF. A test was added to ensure this behavior on Decoder's. Change-Id: I9083c91d9626180d3bcf5c069a017050f3c7c4a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/130556 Run-TryBot: Sam Whited <sam@samwhited.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-02encoding/xml: document HTMLAutoClose and HTMLEntity moreBrad Fitzpatrick
They didn't even have public types, which made them pretty mysterious. Give them types and reference the Decoder, which uses them. Also, refer them qualified by their package name in the examples, as we usually do in example*.go files, which usually use package foo_test specifically so we can show the package names along with the symbols. Change-Id: I50ebbbf43778c1627bfa526f8824f52c7953454f Reviewed-on: https://go-review.googlesource.com/127663 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-08-02encoding/xml: remove some primordial semicolonsBrad Fitzpatrick
Change-Id: I23e5d87648a4091fb4f6616bf80aa6c800974900 Reviewed-on: https://go-review.googlesource.com/127662 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-06-01all: update comment URLs from HTTP to HTTPS, where possibleTim Cooper
Each URL was manually verified to ensure it did not serve up incorrect content. Change-Id: I4dc846227af95a73ee9a3074d0c379ff0fa955df Reviewed-on: https://go-review.googlesource.com/115798 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-05-09encoding/xml: fix valid character rangeArtyom Pervukhin
Section 2.2 of the referenced spec http://www.xml.com/axml/testaxml.htm defines 0xD7FF as a (sub)range boundary, not 0xDF77. Fixes #25172 Change-Id: Ic5a3328cd46ef6474b8e93c4a343dcfba0e6511f Reviewed-on: https://go-review.googlesource.com/109495 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-04-15encoding/xml: remove unnecessary if conditionstengufromsky
Fixes gosimple warning "if err != nil { return err }; return nil' can be simplified to 'return err" Change-Id: Ibbc717fb066ff41ab35c481b6d44980ac809ae09 Reviewed-on: https://go-review.googlesource.com/107018 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-20all: remove duplicate word "the"Ryuma Yoshida
Change-Id: Ia5908e94a6bd362099ca3c63f6ffb7e94457131d GitHub-Last-Rev: 545a40571a912f433546d8c94a9d63459313515d GitHub-Pull-Request: golang/go#23942 Reviewed-on: https://go-review.googlesource.com/95435 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-02-19encoding/xml: simplify slice-growing logic in rawTokenAlberto Donizetti
It appears that old code (from 2009) in xml.(*Decoder).rawToken replicates append's slice-growing functionality by allocating a new, bigger backing array and then calling copy. Simplifying the code by replacing it with a single append call does not seem to hurt performance: name old time/op new time/op delta Marshal-4 11.2µs ± 1% 11.3µs ±10% ~ (p=0.069 n=19+17) Unmarshal-4 28.6µs ± 1% 28.4µs ± 1% -0.60% (p=0.000 n=20+18) name old alloc/op new alloc/op delta Marshal-4 5.78kB ± 0% 5.78kB ± 0% ~ (all equal) Unmarshal-4 8.61kB ± 0% 8.27kB ± 0% -3.90% (p=0.000 n=20+20) name old allocs/op new allocs/op delta Marshal-4 23.0 ± 0% 23.0 ± 0% ~ (all equal) Unmarshal-4 189 ± 0% 190 ± 0% +0.53% (p=0.000 n=20+20) Change-Id: Ie580d1216a44760e611e63dee2c339af5465aea5 Reviewed-on: https://go-review.googlesource.com/86655 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-15encoding/xml: move unexported const out of exported const blockRuss Cox
CL 58210 introduced this constant for reasons I don't understand. It should not be in the exported const block, which will pollute godoc output with a "... unexported" notice. Also since we already have a constant named xmlnsPrefix for "xmlns", it is very confusing to also have xmlNamespacePrefix for "xml". If we must have the constant at all, rename it to xmlPrefix. Change-Id: I15f937454d730005816fcd32b1acca703acf1e51 Reviewed-on: https://go-review.googlesource.com/78121 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-10-30encoding/xml: don't panic when custom Unmarshaler sees StartElementSam Whited
Change-Id: I90aa0a983abd0080f3de75d3340fdb15c1f9ca35 Reviewed-on: https://go-review.googlesource.com/70891 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Sam Whited <sam@samwhited.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-05all: revert "all: prefer strings.IndexByte over strings.Index"Marvin Stenger
This reverts https://golang.org/cl/65930. Fixes #22148 Change-Id: Ie0712621ed89c43bef94417fc32de9af77607760 Reviewed-on: https://go-review.googlesource.com/68430 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-25all: prefer strings.IndexByte over strings.IndexMarvin Stenger
strings.IndexByte was introduced in go1.2 and it can be used effectively wherever the second argument to strings.Index is exactly one byte long. This avoids generating unnecessary string symbols and saves a few calls to strings.Index. Change-Id: I1ab5edb7c4ee9058084cfa57cbcc267c2597e793 Reviewed-on: https://go-review.googlesource.com/65930 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-13encoding/xml: add decode wrapperSam Whited
Fixes #19480 Change-Id: I5a621507279d5bb1f3991b7a412d9a63039d464b Reviewed-on: https://go-review.googlesource.com/38791 Run-TryBot: Sam Whited <sam@samwhited.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-24encoding/xml: improve package based on the suggestions from metalinterKarel Pazdera
Existing code in encoding/xml packages contains code which breaks various linter rules (comments, constant and variable naming, variable shadowing, etc). Fixes #21578 Change-Id: Id4bd9a9be6d5728ce88fb6efe33030ef943c078c Reviewed-on: https://go-review.googlesource.com/58210 Reviewed-by: Sam Whited <sam@samwhited.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Sam Whited <sam@samwhited.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-02-29all: remove public named return values when uselessBrad Fitzpatrick
Named returned values should only be used on public funcs and methods when it contributes to the documentation. Named return values should not be used if they're only saving the programmer a few lines of code inside the body of the function, especially if that means there's stutter in the documentation or it was only there so the programmer could use a naked return statement. (Naked returns should not be used except in very small functions) This change is a manual audit & cleanup of public func signatures. Signatures were not changed if: * the func was private (wouldn't be in public godoc) * the documentation referenced it * the named return value was an interesting name. (i.e. it wasn't simply stutter, repeating the name of the type) There should be no changes in behavior. (At least: none intended) Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109 Reviewed-on: https://go-review.googlesource.com/20024 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-01-24encoding/xml: update docs for TokenRuss Cox
Fixes #13757. Change-Id: I1b52593df8df0e98ce7342767eb34eccecc11761 Reviewed-on: https://go-review.googlesource.com/18854 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-11-25encoding/xml: case-insensitive encoding recognitionGiulio Iotti
From the XML spec: "XML processors should match character encoding names in a case-insensitive way" Fixes #12417. Change-Id: I678c50152a49c14364be62b3f21ab9b9b009b24b Reviewed-on: https://go-review.googlesource.com/14084 Reviewed-by: Russ Cox <rsc@golang.org>
2015-11-25encoding/xml: reject invalid commentsMichal Bohuslávek
Fixes #11112. Change-Id: I16e7363549a0dec8c61addfa14af0866c1fd7c40 Reviewed-on: https://go-review.googlesource.com/14173 Reviewed-by: Russ Cox <rsc@golang.org>
2015-11-25encoding/xml: Add CDATA-wrapper output support to xml.Marshal.Charles Weill
Fixes #12963 Change-Id: Icc50dfb6130fe1e189d45f923c2f7408d3cf9401 Reviewed-on: https://go-review.googlesource.com/16047 Reviewed-by: Russ Cox <rsc@golang.org>
2015-09-10encoding/xml: Return SyntaxError for unmatched root start elements.Robert Stepanek
Currently, the xml.Decoder's Token routine returns successfully for XML input that does not properly close root start elements (and any unclosed descendants). For example, all the following inputs <root> <root><foo> <root><foo></foo> cause Token to return with nil and io.EOF, indicating a successful parse. This change fixes that. It leaves the semantics of RawToken intact. Fixes #11405 Change-Id: I6f1328c410cf41e17de0a93cf357a69f12c2a9f7 Reviewed-on: https://go-review.googlesource.com/14315 Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-07-27encoding/xml: restore Go 1.4 name space behaviorRuss Cox
There is clearly work to do here with respect to xml name spaces, but I don't believe the changes in this cycle are clearly correct. The changes in this cycle have visible impact on the generated xml, possibly breaking existing programs, and yet it's not clear that they are the end of the story: there is still significant confusion about how name spaces work or should work (see #9519, #9775, #8167, #7113). I would like to wait to make breaking changes until we completely understand what the behavior should be and can evaluate the benefit of those breaking changes. My main concern here is that we will break programs in Go 1.5 for the sake of name space adjustments and then while trying to fix those other bugs we'll break programs in Go 1.6 too. Let's wait until we know all the changes we want to make before we decide whether or how to break existing programs. This CL reverts: 5ae822b encoding/xml: minor changes bb7e665 encoding/xml: fix xmlns= behavior 9f9d66d encoding/xml: fix default namespace of tags b69ea01 encoding/xml: fix namespaces in a>b tags 3be158d encoding/xml: encoding name spaces correctly and adjusts tests from a9dddb5 encoding/xml: add more EncodeToken tests. to expect Go 1.4 behavior. I have confirmed that the name space parts of the test suite as of this CL passes against the Go 1.4 encoding/xml package, indicating that this CL successfully restores the Go 1.4 behavior. (Other tests do not, but that's because there were some real bug fixes in this cycle that are being kept. Specifically, the tests that don't pass in Go 1.4 are TestMarshal's NestedAndComment case, TestEncodeToken's encoding of newlines, and TestSimpleUseOfEncodeToken returning an error for invalid token types.) I also checked that the Go 1.4 tests pass when run against this copy of the sources. Fixes #11841. Change-Id: I97de06761038b40388ef6e3a55547ff43edee7cb Reviewed-on: https://go-review.googlesource.com/12570 Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-06-30encoding/xml: fix xmlns= behaviorRoger Peppe
When an xmlns="..." attribute was explicitly generated, it was being ignored because the name space on the attribute was assumed to have been explicitly set (to the empty name space) and it's not possible to have an element in the empty name space when there is a non-empty name space set. We fix this by recording when a default name space has been explicitly set and setting the name space of the element to that so printer.defineNS can do its work correctly. We do not attempt to add our own xmlns="..." attribute when one is explicitly set. We also add tests for EncodeElement, as that's the only way to attain coverage of some of the changed behaviour. Some other test coverage is also increased, although more work remains to be done in this area. This change was jointly developed with Martin Hilton (mhilton on github). Fixes #11431. Change-Id: I7b85e06eea5b18b2c15ec16dcbd92a8e1d6a9a4e Reviewed-on: https://go-review.googlesource.com/11635 Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-18xml: add check of version in document declarationGiulio Iotti
Check that if a version is declared, for example in '<?xml version="XX" ?>', version must be '1.0'. Change-Id: I16ba9f78873a5f31977dcf75ac8e671fe6c08280 Reviewed-on: https://go-review.googlesource.com/8961 Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-27encoding/xml: do not escape newlinesRoger Peppe
There is no need to escape newlines in char data - it makes the XML larger and harder to read. Change-Id: I1c1fcee1bdffc705c7428f89ca90af8085d6fb73 Reviewed-on: https://go-review.googlesource.com/9310 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-02-13encoding/xml: encoding name spaces correctlyRoger Peppe
The current XML printer does not understand the xmlns attribute. This change changes it so that it interprets the xmlns attributes in the tokens being printed, and uses appropriate prefixes. Fixes #7535. Change-Id: I20fae291d20602d37deb41ed42fab4c9a50ec85d Reviewed-on: https://go-review.googlesource.com/2660 Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-02-07encoding/xml: avoid an allocation for tags without attributesBrian Smith
Before, an array of size 4 would always be allocated even if a tag doesn't have any attributes. Now that array is allocated only if needed. benchmark old allocs new allocs delta BenchmarkUnmarshal 191 176 -8.5% Change-Id: I4d214b228883d0a6e892c0d6eb00dfe2da84c116 Reviewed-on: https://go-review.googlesource.com/4160 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>