Skip to content

Commit

Permalink
fix #715 and the related failing tests that were added in the previou…
Browse files Browse the repository at this point in the history
…s commit.
  • Loading branch information
jvshahid committed Jul 5, 2012
1 parent 4b82232 commit 647afce
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ext/java/nokogiri/XmlDocumentFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,26 @@ private static boolean isTag(RubyString ruby_string) {

private static String ignoreNamespaceIfNeeded(XmlDocument doc, String tags) {
if (doc.getDocument() == null) return tags;
Matcher matcher = qname_pattern.matcher(tags);
Map<String, String> rewriteTable = new HashMap<String, String>();
while(matcher.find()) {
// we have to make sure that we don't replace strings in double quotes, e.g.

This comment has been minimized.

Copy link
@benlangfeld

benlangfeld Jul 13, 2012

Contributor

Also need to avoid replacing any text nodes within tags.

// 'urn:xmpp:foospec:barfoo' in '<foobar xmlns="urn:xmpp:foospec:barfoo"/>'
// has to remain the same
String[] parts = tags.split("\"");
for (int partidx = 0; partidx < parts.length; partidx++) {
if (partidx % 2 == 1)
continue;
Matcher matcher = qname_pattern.matcher(parts[partidx]);
while(matcher.find()) {
String qName = matcher.group();
if (doc.getDocument().getDocumentElement() != null) {
NamedNodeMap nodeMap = doc.getDocument().getDocumentElement().getAttributes();
if (!isNamespaceDefined(qName, nodeMap)) {
rewriteTable.put(qName, getLocalPart(qName));
}
} else {
NamedNodeMap nodeMap = doc.getDocument().getDocumentElement().getAttributes();
if (!isNamespaceDefined(qName, nodeMap)) {
rewriteTable.put(qName, getLocalPart(qName));
}
} else {
rewriteTable.put(qName, getLocalPart(qName));
}
}
}
Set<String> keys = rewriteTable.keySet();
for (String key : keys) {
Expand Down

0 comments on commit 647afce

Please sign in to comment.