Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2739843002: DOM: Fix "" handling in Node.lookupNamespaceURI(). (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 * rights reserved. 6 * rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * 10 *
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 context = parentElement(); 1233 context = parentElement();
1234 break; 1234 break;
1235 } 1235 }
1236 1236
1237 if (!context) 1237 if (!context)
1238 return nullAtom; 1238 return nullAtom;
1239 1239
1240 return context->locateNamespacePrefix(namespaceURI); 1240 return context->locateNamespacePrefix(namespaceURI);
1241 } 1241 }
1242 1242
1243 const AtomicString& Node::lookupNamespaceURI(const String& prefix) const { 1243 const AtomicString& Node::lookupNamespaceURI(
1244 const String& specifiedPrefix) const {
1244 // Implemented according to 1245 // Implemented according to
1245 // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorith ms.html#lookupNamespaceURIAlgo 1246 // https://dom.spec.whatwg.org/#dom-node-lookupnamespaceuri
1246 1247
1247 if (!prefix.isNull() && prefix.isEmpty()) 1248 // 1. If prefix is the empty string, then set it to null.
1248 return nullAtom; 1249 String prefix = specifiedPrefix;
1250 if (!specifiedPrefix.isNull() && specifiedPrefix.isEmpty())
1251 prefix = String();
1249 1252
1253 // 2. Return the result of running locate a namespace for the context object
1254 // using prefix.
1255
1256 // https://dom.spec.whatwg.org/#locate-a-namespace
1250 switch (getNodeType()) { 1257 switch (getNodeType()) {
1251 case kElementNode: { 1258 case kElementNode: {
1252 const Element& element = toElement(*this); 1259 const Element& element = toElement(*this);
1253 1260
1261 // 1. If its namespace is not null and its namespace prefix is prefix,
1262 // then return namespace.
1254 if (!element.namespaceURI().isNull() && element.prefix() == prefix) 1263 if (!element.namespaceURI().isNull() && element.prefix() == prefix)
1255 return element.namespaceURI(); 1264 return element.namespaceURI();
1256 1265
1266 // 2. If it has an attribute whose namespace is the XMLNS namespace,
1267 // namespace prefix is "xmlns", and local name is prefix, or if prefix is
1268 // null and it has an attribute whose namespace is the XMLNS namespace,
1269 // namespace prefix is null, and local name is "xmlns", then return its
1270 // value if it is not the empty string, and null otherwise.
1257 AttributeCollection attributes = element.attributes(); 1271 AttributeCollection attributes = element.attributes();
1258 for (const Attribute& attr : attributes) { 1272 for (const Attribute& attr : attributes) {
1259 if (attr.prefix() == xmlnsAtom && attr.localName() == prefix) { 1273 if (attr.prefix() == xmlnsAtom && attr.localName() == prefix) {
1260 if (!attr.value().isEmpty()) 1274 if (!attr.value().isEmpty())
1261 return attr.value(); 1275 return attr.value();
1262 return nullAtom; 1276 return nullAtom;
1263 } 1277 }
1264 if (attr.localName() == xmlnsAtom && prefix.isNull()) { 1278 if (attr.localName() == xmlnsAtom && prefix.isNull()) {
1265 if (!attr.value().isEmpty()) 1279 if (!attr.value().isEmpty())
1266 return attr.value(); 1280 return attr.value();
1267 return nullAtom; 1281 return nullAtom;
1268 } 1282 }
1269 } 1283 }
1270 1284
1285 // 3. If its parent element is null, then return null.
1286 // 4. Return the result of running locate a namespace on its parent
1287 // element using prefix.
1271 if (Element* parent = parentElement()) 1288 if (Element* parent = parentElement())
1272 return parent->lookupNamespaceURI(prefix); 1289 return parent->lookupNamespaceURI(prefix);
1273 return nullAtom; 1290 return nullAtom;
1274 } 1291 }
1275 case kDocumentNode: 1292 case kDocumentNode:
1276 if (Element* de = toDocument(this)->documentElement()) 1293 if (Element* de = toDocument(this)->documentElement())
1277 return de->lookupNamespaceURI(prefix); 1294 return de->lookupNamespaceURI(prefix);
1278 return nullAtom; 1295 return nullAtom;
1279 case kDocumentTypeNode: 1296 case kDocumentTypeNode:
1280 case kDocumentFragmentNode: 1297 case kDocumentFragmentNode:
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 if (node) { 2584 if (node) {
2568 std::stringstream stream; 2585 std::stringstream stream;
2569 node->printNodePathTo(stream); 2586 node->printNodePathTo(stream);
2570 LOG(INFO) << stream.str(); 2587 LOG(INFO) << stream.str();
2571 } else { 2588 } else {
2572 LOG(INFO) << "Cannot showNodePath for <null>"; 2589 LOG(INFO) << "Cannot showNodePath for <null>";
2573 } 2590 }
2574 } 2591 }
2575 2592
2576 #endif 2593 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/external/wpt/dom/nodes/Node-lookupNamespaceURI-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698