summaryrefslogtreecommitdiff
path: root/src/encoding/xml
Commit message (Collapse)AuthorAgeFilesLines
* encoding/xml: replace tinfoMap RWMutex with sync.MapBryan C. Mills2017-04-281-12/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This simplifies the code a bit and provides a modest speedup for Marshal with many CPUs. updates #17973 updates #18177 name old time/op new time/op delta Marshal 15.8µs ± 1% 15.9µs ± 1% +0.67% (p=0.021 n=8+7) Marshal-6 5.76µs ±11% 5.17µs ± 2% -10.36% (p=0.002 n=8+8) Marshal-48 9.88µs ± 5% 7.31µs ± 6% -26.04% (p=0.000 n=8+8) Unmarshal 44.7µs ± 3% 45.1µs ± 5% ~ (p=0.645 n=8+8) Unmarshal-6 12.1µs ± 7% 11.8µs ± 8% ~ (p=0.442 n=8+8) Unmarshal-48 18.7µs ± 3% 18.2µs ± 4% ~ (p=0.054 n=7+8) name old alloc/op new alloc/op delta Marshal 5.78kB ± 0% 5.78kB ± 0% ~ (all equal) Marshal-6 5.78kB ± 0% 5.78kB ± 0% ~ (all equal) Marshal-48 5.78kB ± 0% 5.78kB ± 0% ~ (all equal) Unmarshal 8.58kB ± 0% 8.58kB ± 0% ~ (all equal) Unmarshal-6 8.58kB ± 0% 8.58kB ± 0% ~ (all equal) Unmarshal-48 8.58kB ± 0% 8.58kB ± 0% ~ (p=1.000 n=8+8) name old allocs/op new allocs/op delta Marshal 23.0 ± 0% 23.0 ± 0% ~ (all equal) Marshal-6 23.0 ± 0% 23.0 ± 0% ~ (all equal) Marshal-48 23.0 ± 0% 23.0 ± 0% ~ (all equal) Unmarshal 189 ± 0% 189 ± 0% ~ (all equal) Unmarshal-6 189 ± 0% 189 ± 0% ~ (all equal) Unmarshal-48 189 ± 0% 189 ± 0% ~ (all equal) https://perf.golang.org/search?q=upload:20170427.5 Change-Id: I4ee95a99540d3e4e47e056fff18357efd2cd340a Reviewed-on: https://go-review.googlesource.com/41991 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* encoding/xml: parallelize benchmarksBryan C. Mills2017-04-261-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Results remain comparable with the non-parallel version with -cpu=1: benchmark old ns/op new ns/op delta BenchmarkMarshal 31220 28618 -8.33% BenchmarkMarshal-6 37181 7658 -79.40% BenchmarkUnmarshal 81837 83522 +2.06% BenchmarkUnmarshal-6 96339 18244 -81.06% benchmark old allocs new allocs delta BenchmarkMarshal 23 23 +0.00% BenchmarkMarshal-6 23 23 +0.00% BenchmarkUnmarshal 189 189 +0.00% BenchmarkUnmarshal-6 189 189 +0.00% benchmark old bytes new bytes delta BenchmarkMarshal 5776 5776 +0.00% BenchmarkMarshal-6 5776 5776 +0.00% BenchmarkUnmarshal 8576 8576 +0.00% BenchmarkUnmarshal-6 8576 8576 +0.00% updates #18177 Change-Id: I7e7055a11d18896bd54d7d773f2ec64767cdb4c8 Reviewed-on: https://go-review.googlesource.com/36810 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: unmarshal allow empty, non-string valuesSarah Adams2017-03-222-0/+175
| | | | | | | | | | | | | | When unmarshaling, if an element is empty, eg. '<tag></tag>', and destination type is int, uint, float or bool, do not attempt to parse value (""). Set to its zero value instead. Fixes #13417 Change-Id: I2d79f6d8f39192bb277b1a9129727d5abbb2dd1f Reviewed-on: https://go-review.googlesource.com/38386 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* encoding/xml: format test output using subtestsSam Whited2017-03-221-36/+41
| | | | | | | | Change-Id: I2d155c838935cd8427abd142a462ff4c56829715 Reviewed-on: https://go-review.googlesource.com/37948 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* encoding/xml: remove unused start parameterDaniel Martí2017-03-061-3/+3
| | | | | | | | | | Found by github.com/mvdan/unparam. Change-Id: I5a6664cceeba1cf1c2f3236ddf4db5ce7a64b02a Reviewed-on: https://go-review.googlesource.com/37835 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* encoding/xml: fix incorrect indirect code in chardata, comment, innerxml fieldsRuss Cox2017-02-142-16/+554
| | | | | | | | | | | | | | | | | | | | | | | | | | The new tests in this CL have been checked against Go 1.7 as well and all pass in Go 1.7, with the one exception noted in a comment (an intentional change to omitempty already present before this CL). CL 15684 made the intentional change to omitempty. This CL fixes bugs introduced along the way. Most of these are corner cases that are arguably not that important, but they've always worked all the way back to Go 1, and someone cared enough to file #19063. The most significant problem found while adding tests is that in the case of a nil *string field with `xml:",chardata"`, the existing code silently stops processing not just that field but the entire remainder of the struct. Even if #19063 were not worth fixing, this chardata bug would be. Fixes #19063. Change-Id: I318cf8f9945e1a4615982d9904e109fde577ebf9 Reviewed-on: https://go-review.googlesource.com/36954 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* all: spell "marshal" and "unmarshal" consistentlyDmitri Shuralyov2016-11-125-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The tree is inconsistent about single l vs double l in those words in documentation, test messages, and one error value text. $ git grep -E '[Mm]arshall(|s|er|ers|ed|ing)' | wc -l 42 $ git grep -E '[Mm]arshal(|s|er|ers|ed|ing)' | wc -l 1694 Make it consistently a single l, per earlier decisions. This means contributors won't be confused by misleading precedence, and it helps consistency. Change the spelling in one error value text in newRawAttributes of crypto/x509 package to be consistent. This change was generated with: perl -i -npe 's,([Mm]arshal)l(|s|er|ers|ed|ing),$1$2,' $(git grep -l -E '[Mm]arshall' | grep -v AUTHORS | grep -v CONTRIBUTORS) Updates #12431. Follows https://golang.org/cl/14150. Change-Id: I85d28a2d7692862ccb02d6a09f5d18538b6049a2 Reviewed-on: https://go-review.googlesource.com/33017 Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: check type when unmarshaling innerxml fieldQuentin Smith2016-11-092-1/+22
| | | | | | | | | | | | | | | We only support unmarshaling into a string or a []byte, but we previously would try (and panic while) setting a slice of a different type. The docs say ",innerxml" is ignored if the type is not string or []byte, so do that for other slices as well. Fixes #15600. Change-Id: Ia64815945a14c3d04a0a45ccf413e38b58a69416 Reviewed-on: https://go-review.googlesource.com/32919 Run-TryBot: Quentin Smith <quentin@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: add wildcard support for collecting all attributesRuss Cox2016-10-184-27/+140
| | | | | | | | | | | | | | | | | | | | | | | - Like ",any" for elements, add ",any,attr" for attributes to allow a mop-up field that gets any otherwise unmapped attributes. - Map attributes to fields of type slice by extending the slice, just like for elements. - Allow storing an attribute into an xml.Attr directly, to provide a way to record the name. Combined, these three independent features allow AllAttrs []Attr `xml:",any,attr"` to collect all attributes not otherwise spoken for in a particular struct. Tests based on CL 16292 by Charles Weill. Fixes #3633. Change-Id: I2d75817f17ca8752d7df188080a407836af92611 Reviewed-on: https://go-review.googlesource.com/30946 Reviewed-by: Quentin Smith <quentin@golang.org>
* encoding/xml: split attribute marshaling into its own methodRuss Cox2016-10-131-62/+70
| | | | | | | | | | No functional changes here. Just makes next CL easier to read. Change-Id: Icf7b2281b4da6cb59ff4edff05943b2ee288576a Reviewed-on: https://go-review.googlesource.com/30945 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* encoding/xml: prevent omitempty from omitting non-nil pointers to empty valuesAllan Simon2016-10-132-9/+17
| | | | | | | | | | | | | | There was an inconsistency between the (json encoding + documentation) and the xml encoding implementation. Pointer to an empty value was not being serialized (i.e simply ignored). Which had the effect of making impossible to have a struct with a string field for which we wanted to serialize the value "" Fixes #5452 Change-Id: Id858701801158409be01e962d2cda843424bd22a Reviewed-on: https://go-review.googlesource.com/15684 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: do not ignore error return from copyValueEric Lagergren2016-08-222-5/+17
| | | | | | | | | | | | | | | The error return from copyValue was ignored causing some XML attribute parsing to swallow an error. Additionally, type MyMarshalerAttrTest had no UnmarshalXMLAttr method causing marshalTests not to be symmetrical and the test suite to fail for test case 101. Fixes #16158 Change-Id: Icebc505295a2c656ca4b42ba37bb0957dd7260c6 Reviewed-on: https://go-review.googlesource.com/27455 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: update docs to follow conventionSam Whited2016-07-062-6/+6
| | | | | | | | | | Fixes #8833 Change-Id: I4523a1de112ed02371504e27882659bce8028a45 Reviewed-on: https://go-review.googlesource.com/24745 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: use bytes.Equal, bytes.Contains and strings.ContainsDominik Honnef2016-04-011-1/+1
| | | | | | | Change-Id: Iba82a5bd3846f7ab038cc10ec72ff6bcd2c0b484 Reviewed-on: https://go-review.googlesource.com/21377 Run-TryBot: Dave Cheney <dave@cheney.net> Reviewed-by: Dave Cheney <dave@cheney.net>
* all: delete dead non-test codeDominik Honnef2016-03-251-4/+3
| | | | | | | | | | | | | | | | | | | | | | | This change removes a lot of dead code. Some of the code has never been used, not even when it was first commited. The rest shouldn't have survived refactors. This change doesn't remove unused routines helpful for debugging, nor does it remove code that's used in commented out blocks of code that are only unused temporarily. Furthermore, unused constants weren't removed when they were part of a set of constants from specifications. One noteworthy omission from this CL are about 1000 lines of unused code in cmd/fix, 700 lines of which are the typechecker, which hasn't been used ever since the pre-Go 1 fixes have been removed. I wasn't sure if this code should stick around for future uses of cmd/fix or be culled as well. Change-Id: Ib714bc7e487edc11ad23ba1c3222d1fd02e4a549 Reviewed-on: https://go-review.googlesource.com/20926 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: delete dead test codeDominik Honnef2016-03-211-6/+0
| | | | | | | | | | This deletes unused code and helpers from tests. Change-Id: Ie31d46115f558ceb8da6efbf90c3c204e03b0d7e Reviewed-on: https://go-review.googlesource.com/20927 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-023-13/+13
| | | | | | | | | | | | | | | | | | | | 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>
* all: make copyright headers consistent with one space after periodBrad Fitzpatrick2016-03-014-4/+4
| | | | | | | | | | | | | | | | | | | | | | This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: remove public named return values when uselessBrad Fitzpatrick2016-02-291-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* all: replace strings.Index with strings.Contains where possibleNathan VanBenschoten2016-02-191-1/+1
| | | | | | | Change-Id: Ia613f1c37bfce800ece0533a5326fca91d99a66a Reviewed-on: https://go-review.googlesource.com/18120 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org>
* encoding/xml: update docs for TokenRuss Cox2016-01-241-1/+2
| | | | | | | | | | 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>
* encoding/xml: document new chardata tagRuss Cox2015-12-031-0/+2
| | | | | | | | | Followup to CL 16047. For #12963. Change-Id: I596cd5109b25a4079b966427411860fde8b9b54a Reviewed-on: https://go-review.googlesource.com/17232 Reviewed-by: David Crawshaw <crawshaw@golang.org>
* encoding/xml: case-insensitive encoding recognitionGiulio Iotti2015-11-252-1/+33
| | | | | | | | | | | 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>
* encoding/xml: reject invalid commentsMichal Bohuslávek2015-11-252-1/+27
| | | | | | | | Fixes #11112. Change-Id: I16e7363549a0dec8c61addfa14af0866c1fd7c40 Reviewed-on: https://go-review.googlesource.com/14173 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: Add CDATA-wrapper output support to xml.Marshal.Charles Weill2015-11-255-12/+120
| | | | | | | | Fixes #12963 Change-Id: Icc50dfb6130fe1e189d45f923c2f7408d3cf9401 Reviewed-on: https://go-review.googlesource.com/16047 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: check for exported fields in embedded structsMarcel van Lohuizen2015-10-262-1/+11
| | | | | | | | | | Addresses issue #12367. Must be checked in before CL 14010. Change-Id: I4523a1de112ed02371504e27882659bce8028a9f Reviewed-on: https://go-review.googlesource.com/14012 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/base64,xml: map/slice literals janitoringDidier Spezia2015-09-111-1/+1
| | | | | | | | | Simplify slice/map literal expressions. Caught with gofmt -d -s, fixed with gofmt -w -s Change-Id: I639cfb02b1f57dea4087863df3995889c9371529 Reviewed-on: https://go-review.googlesource.com/13837 Reviewed-by: Andrew Gerrand <adg@golang.org>
* encoding/xml: Return SyntaxError for unmatched root start elements.Robert Stepanek2015-09-102-0/+24
| | | | | | | | | | | | | | | | | | | | | 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>
* encoding/xml: fix race using finfo.parents in s.trimRuss Cox2015-07-271-1/+1
| | | | | | | | | | | | | | | | | | | | | This race was identified in #9796, but a sequence of fixes proposed in golang.org/cl/4152 were rolled into golang.org/cl/5910 which both fixed the race and modified the name space behavior. We rolled back the name space changes and lost the race fix. Fix the race separate from the name space changes, following the suggestion made by Roger Peppe in https://go-review.googlesource.com/#/c/4152/7/src/encoding/xml/marshal.go@897 Fixes #9796. Fixes #11885. Change-Id: Ib2b68982da83dee9e04db8b8465a8295259bba46 Reviewed-on: https://go-review.googlesource.com/12687 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Russ Cox <rsc@golang.org>
* encoding/xml: restore Go 1.4 name space behaviorRuss Cox2015-07-275-687/+209
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* encoding/xml: EncodeToken silently eats tokens with invalid typeDidier Spezia2015-07-232-0/+35
| | | | | | | | | | | | | | | | | | | | | | EncodeToken takes a Token (i.e. an interface{}) as a parameter, and expects a value of type StartElement, EndElement, CharData, Comment, ProcInst, or Directive. If a pointer is passed instead, or any type which does not match this list, the token is silently ignored. Added a default case in the type switch to issue a proper error when the type is invalid. The behavior could be later improved by allowing pointers to token to be accepted as well, but not for go1.5. Fixes #11719 Change-Id: Ifd13c1563450b474acf66d57669fdccba76c1949 Reviewed-on: https://go-review.googlesource.com/12252 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: improve marshaller sanity checks of directivesDidier Spezia2015-07-152-3/+82
| | | | | | | | | | | | | | | | | When building a directive, the current sanity check prevents a '>' to be used, which makes a DOCTYPE directive with an internal subset be rejected. It is accepted by the parser though, so what can be parsed cannot be encoded. Improved the corresponding sanity check to mirror the behavior of the parser (in the way it handles angle brackets, quotes, and comments). Fixes #10158 Change-Id: Ieffea9f870f2694548e12897f8f47babc0ea4414 Reviewed-on: https://go-review.googlesource.com/11630 Reviewed-by: Russ Cox <rsc@golang.org>
* encoding/xml: minor changesRoger Peppe2015-07-011-20/+20
| | | | | | | | | Changes suggested by Nigel Tao in https://go-review.googlesource.com/#/c/11635 after that had been submitted. Change-Id: I7b28e1c8488c8565399a8017453dc7ff1fd215e8 Reviewed-on: https://go-review.googlesource.com/11832 Reviewed-by: Nigel Tao <nigeltao@golang.org>
* encoding/xml: fix xmlns= behaviorRoger Peppe2015-06-303-78/+269
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* xml: add check of version in document declarationGiulio Iotti2015-06-182-15/+24
| | | | | | | | | 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>
* encoding/xml: Reset the parent stack before printing a chardata or comment ↵Hajime Hoshi2015-06-042-0/+24
| | | | | | | | | | | | | | | | field in a struct This CL resets the parent stack when printing a character or comment field struct. In the case of XML elements, the previous parents stack must be considered. However, charadata or comment fields can't be printed in other fields so it seems required to reset the parent stack each time a chardata or comment field is printed. Fixes #5072 Change-Id: I84f61c9bfce94133cd0c076c11211b9be5b4b1ac Reviewed-on: https://go-review.googlesource.com/9910 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: roger peppe <rogpeppe@gmail.com>
* encoding/xml: do not escape newlinesRoger Peppe2015-04-273-2/+12
| | | | | | | | | | 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>
* encoding/xml: fix default namespace of tagsRoger Peppe2015-03-092-0/+10
| | | | | | | | | | | | | | | | The struct XMLName sets the default namespace, but that's not good enough for nested tags, because an earlier tag can set the implicit parents of a subsequent tag. This change makes sure that we always explicitly set the namespace on a tag when possible. See https://go-review.googlesource.com/#/c/5910/4/src/encoding/xml/marshal_test.go@628 for discussion. Change-Id: If1afc536471c0be83e5dd80381b598476ea3f44d Reviewed-on: https://go-review.googlesource.com/6927 Reviewed-by: Nigel Tao <nigeltao@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net>
* encoding/xml: fix namespaces in a>b tagsRoger Peppe2015-03-032-48/+86
| | | | | | | | | | | | | | Previously, if there was a namespace defined on a a>b tag, the namespace was ignored when printing the parent elements. This fixes that, and also fixes the racy behaviour of printerStack.trim as discussed in https://go-review.googlesource.com/#/c/4152/10 . Fixes #9796. Change-Id: I75f97f67c08bbee151d1e0970f8462dd0f4511ef Reviewed-on: https://go-review.googlesource.com/5910 Reviewed-by: Nigel Tao <nigeltao@golang.org>
* encoding/xml: add more marshalTests tests.Nigel Tao2015-02-251-1/+72
| | | | | | | | | | There are no behavior changes in this CL, only specifying the status quo. A follow-up CL, https://go-review.googlesource.com/#/c/5910/, will change marshaling behavior. Change-Id: Ib3f4d62e8c4758da2f11a6d26b285c10d3b0d98a Reviewed-on: https://go-review.googlesource.com/6040 Reviewed-by: Andrew Gerrand <adg@golang.org>
* encoding/xml: encoding name spaces correctlyRoger Peppe2015-02-134-87/+344
| | | | | | | | | | | | | 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>
* encoding/xml: add more EncodeToken tests.Nigel Tao2015-02-091-25/+347
| | | | | | | | | | There are no behavior changes in this CL, only specifying the status quo. A follow-up CL, https://go-review.googlesource.com/#/c/2660/, will change the EncodeToken behavior. Change-Id: I6ecbcfb05ae681de71fa1099d054df2826ed4acb Reviewed-on: https://go-review.googlesource.com/4167 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: avoid an allocation for tags without attributesBrian Smith2015-02-071-2/+6
| | | | | | | | | | | | | 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>
* all: don't refer to code.google.com/p/go{,-wiki}/Péter Surányi2015-02-061-1/+1
| | | | | | | | | | Only documentation / comment changes. Update references to point to golang.org permalinks or go.googlesource.com/go. References in historical release notes under doc are left as is. Change-Id: Icfc14e4998723e2c2d48f9877a91c5abef6794ea Reviewed-on: https://go-review.googlesource.com/4060 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* encoding/xml: remove unnecessary memory allocation in UnmarshalDmitry Vyukov2015-01-152-4/+6
| | | | | | | | | | | | benchmark old ns/op new ns/op delta BenchmarkUnmarshal 75256 72626 -3.49% benchmark old allocs new allocs delta BenchmarkUnmarshal 259 219 -15.44% Change-Id: I7fd30739b045e35b95e6ef6a8ef2f15b0dd6839c Reviewed-on: https://go-review.googlesource.com/2758 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* encoding/xml: remove SyntaxError.ByteRuss Cox2014-12-051-1/+0
| | | | | | | | | | It is unused. It was introduced in the CL that added InputOffset. I suspect it was an editing mistake. LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/182580043
* build: move package sources from src/pkg to srcRuss Cox2014-09-089-0/+6875
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.