@@ -183,21 +183,33 @@ public function encode() {
183183 */
184184 private function installExtension ($ extension , $ profile_dir ) {
185185 $ temp_dir = $ this ->createTempDirectory ('WebDriverFirefoxProfileExtension ' );
186-
187- $ this ->extractTo ($ extension , $ temp_dir );
188-
189- $ install_rdf_path = $ temp_dir .'/install.rdf ' ;
190- // This is a hacky way to parse the id since there is no offical
191- // RDF parser library.
192- $ matches = array ();
193- $ xml = file_get_contents ($ install_rdf_path );
194- preg_match ('#<em:id>([^<]+)</em:id># ' , $ xml , $ matches );
195- $ ext_dir = $ profile_dir .'/extensions/ ' .$ matches [1 ];
196-
197- mkdir ($ ext_dir , 0777 , true );
198-
199- $ this ->extractTo ($ extension , $ ext_dir );
200-
186+ $ this ->extractTo ($ extension , $ temp_dir );
187+
188+ // This is a hacky way to parse the id since there is no offical RDF parser library.
189+ // Find the correct namespace for the id element.
190+ $ install_rdf_path = $ temp_dir .'/install.rdf ' ;
191+ $ xml = simplexml_load_file ($ install_rdf_path );
192+ $ ns = $ xml ->getDocNamespaces ();
193+ $ prefix = '' ;
194+ if (!empty ($ ns )) {
195+ foreach ($ ns as $ key => $ value ) {
196+ if (strpos ($ value , '//www.mozilla.org/2004/em-rdf ' ) > 0 ) {
197+ if ($ key != '' ) {
198+ $ prefix = $ key . ': ' ; // Separate the namespace from the name.
199+ }
200+ break ;
201+ }
202+ }
203+ }
204+ // Get the extension id from the install manifest.
205+ $ matches = array ();
206+ preg_match ('#< ' .$ prefix .'id>([^<]+)</ ' .$ prefix .'id># ' , $ xml ->asXML (), $ matches );
207+ if (isset ($ matches [1 ])) {
208+ $ ext_dir = $ profile_dir .'/extensions/ ' .$ matches [1 ];
209+ mkdir ($ ext_dir , 0777 , true );
210+ $ this ->extractTo ($ extension , $ ext_dir );
211+ }
212+
201213 // clean up
202214 $ this ->deleteDirectory ($ temp_dir );
203215
0 commit comments