Skip to content

Commit 000621a

Browse files
committed
rb: Handle namespaces in install manifest of Firefox addon
Closes #1145
1 parent 7beb574 commit 000621a

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

rb/CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Ruby:
55
* Removed dependency on "multi_json" (issue 1632)
6+
* Properly handle namespaces in install manifest of Firefox add-ons (issue 1143)
67

78
2.52.0 (2016-02-12)
89
===================

rb/lib/selenium/webdriver/firefox/extension.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ module Selenium
2121
module WebDriver
2222
module Firefox
2323

24+
#
2425
# @api private
26+
#
27+
2528
class Extension
29+
NAMESPACE = 'http://www.mozilla.org/2004/em-rdf#'
30+
2631
def initialize(path)
2732
unless File.exist?(path)
2833
raise Error::WebDriverError, "could not find extension at #{path.inspect}"
@@ -61,20 +66,17 @@ def create_root
6166
def read_id_from_install_rdf(directory)
6267
rdf_path = File.join(directory, "install.rdf")
6368
doc = REXML::Document.new(File.read(rdf_path))
69+
namespace = doc.root.namespaces.key(NAMESPACE)
6470

65-
id_node = REXML::XPath.first(doc, "//em:id")
66-
67-
if id_node
68-
id_node.text
69-
else
70-
attr_node = REXML::XPath.first(doc, "//@em:id")
71+
if namespace
72+
id_node = REXML::XPath.first(doc, "//#{namespace}:id")
73+
return id_node.text if id_node
7174

72-
if attr_node.nil?
73-
raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
74-
end
75-
76-
attr_node.value
75+
attr_node = REXML::XPath.first(doc, "//@#{namespace}:id")
76+
return attr_node.value if attr_node
7777
end
78+
79+
raise Error::WebDriverError, "cannot locate extension id in #{rdf_path}"
7880
end
7981

8082
end # Extension

rb/spec/unit/selenium/webdriver/firefox/extension_spec.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end
6060
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
6161
end
6262

63+
it 'finds the rdf extension id regardless of namespace' do
64+
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML
65+
<?xml version="1.0"?>
66+
<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">
67+
<r:Description about="urn:mozilla:install-manifest">
68+
<id>{f5198635-4eb3-47a5-b6a5-366b15cd2107}</id>
69+
</r:Description>
70+
</r:RDF>
71+
XML
72+
73+
expect(extension.read_id('/foo')).to eq('{f5198635-4eb3-47a5-b6a5-366b15cd2107}')
74+
end
75+
6376
it 'raises if the node id is not found' do
6477
allow(File).to receive(:read).with('/foo/install.rdf').and_return <<-XML
6578
<?xml version="1.0"?>
@@ -68,10 +81,8 @@ def ext.read_id(dir); read_id_from_install_rdf(dir); end
6881

6982
expect { extension.read_id('/foo') }.to raise_error(Error::WebDriverError)
7083
end
71-
7284
end
7385

7486
end # Firefox
7587
end # WebDriver
7688
end # Selenium
77-

0 commit comments

Comments
 (0)