Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3671)

Issue 7350048: code review 7350048: encoding/xml: fix unmarshalling tags with namespace

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 2 months ago by c9s
Modified:
10 years, 10 months ago
Reviewers:
dave, golang-dev, rsc, bradfitz
CC:
golang-dev
Visibility:
Public.

Description

encoding/xml: fix unmarshalling tags with namespace Add a failing test: TestUnmarshalXmlTagWithNamespace and fixed unmarshal tags with namespace. xml.Unmarshal does not unmarshal tags like <sparkle:releaseNotesLink> for `xml:"sparkel:releaseNotesLink"`. for example: type Item struct { // ... SparkleReleaseNotesLink string `xml:"sparkle:releaseNotesLink"` } The above code does not work. If we simply write: type Item struct { // ... SparkleReleaseNotesLink string `xml:"releaseNotesLink"` } this works, but when encoding XML back, we still need the namespace. (encoding tags with namespace works fine currently) In the unmarshal func in read.go, it replaces the namespace name with namespace value, so that we can't compare the fieldinfo with the token. I did a minimal approach to solve this: 1. Added a nsResolve map[string]string to resolve namespace quickly and didn't change the original behavior of translating namespace name. 2. When the field don't match with the token, check the token.Space If the token.Space exists, resolve the namespace value and compare it ("ns:field") with the field name. By doing this, we can marshal the struct into into XML correctly, The below XML is generated by xml.Unmarshal func (with this fix): <channel> <item> <title>Version 2.0 (2 bugs fixed; 3 new features)</title> <sparkle:releaseNotesLink>http://you.com/app/2.0.html</sparkle:releaseNotesLink> <enclosure url="http://you.com/app/Your Great App 2.0.zip" length="1623481" sparkle:version="2.0" sparkle:dsaSignature="BAFJW4B6B1K1JyW30nbkBwainOzrN6EQuAh"></enclosure> </item> </channel>

Patch Set 1 : diff -r bfaaa2075564 https://code.google.com/p/go/ #

Patch Set 2 : diff -r 38271c4ce682 https://code.google.com/p/go/ #

Patch Set 3 : diff -r e93de8482d59 https://code.google.com/p/go/ #

Patch Set 4 : diff -r 28f7394b058f https://code.google.com/p/go/ #

Patch Set 5 : diff -r 3391481b6373 https://code.google.com/p/go/ #

Total comments: 9

Patch Set 6 : diff -r e14ccb3e4514 https://code.google.com/p/go/ #

Patch Set 7 : diff -r e14ccb3e4514 https://code.google.com/p/go/ #

Total comments: 1

Patch Set 8 : diff -r e14ccb3e4514 https://code.google.com/p/go/ #

Total comments: 10

Patch Set 9 : diff -r ddf29de95e90 https://code.google.com/p/go/ #

Total comments: 1

Patch Set 10 : diff -r ddf29de95e90 https://code.google.com/p/go/ #

Patch Set 11 : diff -r 526fb7125a2f https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+92 lines, -0 lines) Patch
M src/pkg/encoding/xml/read.go View 1 2 3 4 5 6 7 8 2 chunks +13 lines, -0 lines 0 comments Download
M src/pkg/encoding/xml/read_test.go View 1 2 3 4 5 6 7 8 9 1 chunk +79 lines, -0 lines 0 comments Download

Messages

Total messages: 30
c9s
Please take a look
11 years, 2 months ago (2013-02-18 17:40:18 UTC) #1
c9s
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go/
11 years, 2 months ago (2013-02-19 03:12:44 UTC) #2
c9s
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-19 03:44:20 UTC) #3
dave_cheney.net
On 2013/02/19 03:44:20, c9s wrote: > Hello mailto:golang-dev@googlegroups.com (cc: mailto:golang-dev@googlegroups.com), > > Please take another ...
11 years, 2 months ago (2013-02-19 04:07:49 UTC) #4
c9s
Sorry I guess I had some problem with hg. let me do that. On 2013/02/19 ...
11 years, 2 months ago (2013-02-19 04:09:18 UTC) #5
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-19 04:09:42 UTC) #6
c9s
I have a question. the tests in the go repository are passed. but in my ...
11 years, 2 months ago (2013-02-19 04:15:04 UTC) #7
dave_cheney.net
Without knowing the details of your system, I'd say you had two versions of Go ...
11 years, 2 months ago (2013-02-19 04:17:18 UTC) #8
c9s
Weird , I have only one version Go installed (from hg), which is located at ...
11 years, 2 months ago (2013-02-19 06:42:23 UTC) #9
c9s
Ah, I have a symbol link from ~/src/go/go to /usr/local/go , does this affect ? ...
11 years, 2 months ago (2013-02-19 07:00:11 UTC) #10
c9s
I just looked into the code, and found that getTypeInfo is actually taking namespace information ...
11 years, 2 months ago (2013-02-19 09:51:50 UTC) #11
c9s
Please take a look at the changes, I provided a xml test case for namespace ...
11 years, 2 months ago (2013-02-19 09:59:09 UTC) #12
c9s
Hi dfc, I have a few questions about the XML namespace behavior. 1. why do ...
11 years, 2 months ago (2013-02-19 10:19:51 UTC) #13
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-19 10:31:04 UTC) #14
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 07:36:11 UTC) #15
bradfitz
https://codereview.appspot.com/7350048/diff/21001/src/pkg/encoding/xml/read.go File src/pkg/encoding/xml/read.go (right): https://codereview.appspot.com/7350048/diff/21001/src/pkg/encoding/xml/read.go#newcode142 src/pkg/encoding/xml/read.go:142: remove this extra whitespace https://codereview.appspot.com/7350048/diff/21001/src/pkg/encoding/xml/read.go#newcode241 src/pkg/encoding/xml/read.go:241: and here https://codereview.appspot.com/7350048/diff/21001/src/pkg/encoding/xml/read.go#newcode269 ...
11 years, 2 months ago (2013-02-21 15:40:58 UTC) #16
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 17:03:48 UTC) #17
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 17:04:51 UTC) #18
bradfitz
First line of your commit message should be shorter. It doesn't need to mention adding ...
11 years, 2 months ago (2013-02-21 17:21:40 UTC) #19
c9s
Hi Bradfitz, Thanks for reviewing this patch, I will fix this up soon. On 2013/02/21 ...
11 years, 2 months ago (2013-02-21 17:23:15 UTC) #20
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 17:28:23 UTC) #21
bradfitz
https://codereview.appspot.com/7350048/diff/33003/src/pkg/encoding/xml/read.go File src/pkg/encoding/xml/read.go (right): https://codereview.appspot.com/7350048/diff/33003/src/pkg/encoding/xml/read.go#newcode271 src/pkg/encoding/xml/read.go:271: // for attributes with namespace, we resovle the namespace ...
11 years, 2 months ago (2013-02-21 18:29:53 UTC) #22
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 18:40:17 UTC) #23
c9s
Thanks for your patience. I've fixed them all. :-) On 2013/02/21 18:29:53, bradfitz wrote: > ...
11 years, 2 months ago (2013-02-21 18:41:11 UTC) #24
bradfitz
Okay, I'm now done reviewing this for style. Leaving for Russ or somebody who knows ...
11 years, 2 months ago (2013-02-21 18:42:16 UTC) #25
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-21 18:44:07 UTC) #26
c9s
Hello golang-dev@googlegroups.com, dave@cheney.net, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 2 months ago (2013-02-23 08:45:44 UTC) #27
rsc
Sorry, I missed this CL and fixed the attribute problem as part of cleaning up ...
11 years, 1 month ago (2013-03-12 13:28:18 UTC) #28
c9s
Thank you for reviewing this patch. looking forward to see this namespace issue to be ...
11 years, 1 month ago (2013-03-12 13:50:34 UTC) #29
bradfitz
10 years, 10 months ago (2013-06-05 22:24:00 UTC) #30
R=close

Resolved as part of CL 7227056
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b