nokogiri 1.6.8.rc3-x64-mingw32 → 1.6.8-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10b1fb20f92b9821c76135ccbbc459a0cbc21853
4
- data.tar.gz: 5fcdca76e291f983333bdf6813e4ee800697049d
3
+ metadata.gz: 900d21e9d656fed308ae628ca39496031fadf0b3
4
+ data.tar.gz: 7d303966f06d83bf9d43a64db1dc8eb3203a5799
5
5
  SHA512:
6
- metadata.gz: 20a44cd13c329732a12c17a6e92a2f20b8dcd2a74a32f91fb8a3914ab7a3e8badf78d22f73c223a53cb8420452506ca611e2371695e21e45afe014d936d5fae5
7
- data.tar.gz: 8a61f1ca30617a9dcdfb506e691d86e30e46f2aa27da4f08fa068eb2ef0850e05756b8d218ecca466f97a6bcb12b9d6a2deac77adb184896f5b4dec8606bead7
6
+ metadata.gz: 70f7fd754a3263173bc1c9084de48969b2e3dd82b9aad2375add1dd10d847bcd83fd1cd7b76752bfa8cc3e989a4f8b2054219c48c0f6273c977d10f485faaefb
7
+ data.tar.gz: 18e188164c231d0b219cfc1210a719125945c05710311f9453653b6cf740806ffbe09e0774f2f68f1f46f4af76cc6a3140f3608413bac13345e0b8499f81cee3
data/.travis.yml CHANGED
@@ -10,8 +10,9 @@ rvm:
10
10
  - 2.2.3
11
11
  - 2.3.0
12
12
  - jruby-19mode
13
- - jruby-1.7.23
13
+ - jruby
14
14
  - jruby-9.0.4.0
15
+ - jruby-head
15
16
  - rbx-19mode
16
17
  - rbx-2
17
18
 
@@ -24,13 +25,14 @@ matrix:
24
25
  # https://github.com/travis-ci/travis-ci/issues/5361
25
26
  - os: osx
26
27
  rvm: 2.3.0
28
+ - rvm: jruby-head
27
29
  exclude:
28
30
  - os: osx
29
31
  rvm: ruby-1.9.2
30
32
  - os: osx
31
33
  rvm: jruby-19mode
32
34
  - os: osx
33
- rvm: jruby-1.7.23
35
+ rvm: jruby
34
36
  - os: osx
35
37
  rvm: jruby-9.0.4.0
36
38
  - os: osx
@@ -42,7 +44,7 @@ notifications:
42
44
  irc:
43
45
  channels:
44
46
  - "chat.freenode.net#nokogiri"
45
- on_success: change
47
+ on_success: always
46
48
  on_failure: always
47
49
  template:
48
50
  - "%{repository} (%{branch}:%{commit} by %{author}): %{message} (%{build_url})"
data/CHANGELOG.rdoc CHANGED
@@ -1,10 +1,24 @@
1
1
  === 1.6.8 / unreleased
2
2
 
3
- ==== Security Note
3
+ ==== Security Notes
4
+
5
+ [MRI] Bundled libxml2 is upgraded to 2.9.4, which fixes many security issues. Many of these had previously been patched in the vendored libxml 2.9.2 in the 1.6.7.x branch, but some are newer.
6
+
7
+ See these libxml2 email posts for more:
8
+
9
+ * https://mail.gnome.org/archives/xml/2015-November/msg00012.html
10
+ * https://mail.gnome.org/archives/xml/2016-May/msg00023.html
11
+
12
+ For a more detailed analysis, you may care to read Canonical's take on these security issues:
13
+
14
+ * http://www.ubuntu.com/usn/usn-2994-1
15
+
16
+
17
+ [MRI] Bundled libxslt is upgraded to 1.1.29, which fixes a security issue as well as many long-known outstanding bugs, some features, some portability improvements, and general cleanup.
18
+
19
+ See this libxslt email post for more:
4
20
 
5
- * (MRI) Bundled Libxml2 is upgraded to 2.9.3, which fixes a series of security issues.
6
- These security issues had been patched in the vendored libxml 2.9.2 in the 1.6.7.x branch.
7
- See https://mail.gnome.org/archives/xml/2015-November/msg00012.html for more.
21
+ * https://mail.gnome.org/archives/xslt/2016-May/msg00004.html
8
22
 
9
23
 
10
24
  ==== Features
@@ -16,19 +30,28 @@ Several changes were made to improve performance:
16
30
  * Use Symbol#to_proc where we weren't previously. (#1296) (Thanks, Bruno Sutic!)
17
31
  * XML::DTD#each uses implicit block calls. (Thanks, @glaucocustodio!)
18
32
  * Fall back to the `pkg-config` gem if we're having trouble finding the system libxml2. This should help many FreeBSD users. (#1417)
33
+ * Set document encoding appropriately even on blank document. (#1043) (Thanks, @batter!)
19
34
 
20
35
 
21
36
  ==== Bug Fixes
22
37
 
38
+ * [JRuby] fix slow add_child (#692)
23
39
  * [JRuby] fix load errors when deploying to JRuby/Torquebox (#1114) (Thanks, @atambo and @jvshahid!)
24
40
  * [JRuby] fix NPE when inspecting nodes returned by NodeSet#drop (#1042) (Thanks, @mkristian!)
25
41
  * [JRuby] fix nil attriubte node's namespace in reader (#1327) (Thanks, @codekitchen!)
26
42
  * [JRuby] fix Nokogiri munging unicode characters that require more than 2 bytes (#1113) (Thanks, @mkristian!)
43
+ * [JRuby] allow unlinking an unparented node (#1112, #1152) (Thanks, @esse!)
44
+ * [JRuby] allow Fragment parsing on a frozen string (#444, #1077)
45
+ * [JRuby] HTML `style` tags are no longer encoded (#1316) (Thanks, @tbeauvais!)
27
46
  * [MRI] fix assertion failure while accessing attribute node's namespace in reader (#843) (Thanks, @2potatocakes!)
28
47
  * [MRI] fix issue with GCing namespace nodes returned in an xpath query. (#1155)
29
48
  * [MRI] Ensure C strings are null-terminated. (#1381)
30
49
  * [MRI] Ensure Rubygems is loaded before using mini_portile2 at installation. (#1393, #1411) (Thanks, @JonRowe!)
31
50
  * [MRI] Handling another edge case where the `libxml-ruby` gem's global callbacks were smashing the heap. (#1426). (Thanks to @bbergstrom for providing an isolated test case!)
51
+ * [MRI] Ensure encodings are passed to Sax::Parser xmldecl callback. (#844)
52
+ * [MRI] Ensure default ns prefix is applied correctly when reparenting nodes to another document. (#391) (Thanks, @ylecuyer!)
53
+ * [MRI] Ensure Reader handles non-existent attributes as expected. (#1254) (Thanks, @ccutrer!)
54
+ * [MRI] Cleanup around namespace handling when reparenting nodes. (#1332, #1333, #1444) (Thanks, @cuttrer and @bradleybeddoes!)
32
55
  * unescape special characters in CSS queries (#1303) (Thanks, @twalpole!)
33
56
  * consistently handle empty documents (#1349)
34
57
  * Update to mini_portile2 2.1.0 to address whitespace-handling during patching. (#1402)
data/CONTRIBUTING.md CHANGED
@@ -1,4 +1,4 @@
1
- # Issue and Pull Request Guidlines
1
+ # Issue and Pull Request Guidelines
2
2
 
3
3
  Thank you for getting involved in making Nokogiri better!
4
4
 
data/Gemfile CHANGED
@@ -8,16 +8,16 @@ gem "mini_portile2", "~>2.1.0"
8
8
  gem "pkg-config", "~>1.1.7"
9
9
 
10
10
  gem "rdoc", "~>4.0", :group => [:development, :test]
11
- gem "hoe-bundler", ">=1.1", :group => [:development, :test]
11
+ gem "hoe-bundler", "~>1.2.0", :group => [:development, :test]
12
12
  gem "hoe-debugging", "~>1.2.1", :group => [:development, :test]
13
- gem "hoe-gemspec", ">=1.0", :group => [:development, :test]
14
- gem "hoe-git", ">=1.4", :group => [:development, :test]
15
- gem "minitest", "~>2.2.2", :group => [:development, :test]
16
- gem "rake", ">=0.9", :group => [:development, :test]
13
+ gem "hoe-gemspec", "~>1.0.0", :group => [:development, :test]
14
+ gem "hoe-git", "~>1.6.0", :group => [:development, :test]
15
+ gem "minitest", "~>5.8.4", :group => [:development, :test]
16
+ gem "rake", "~>10.5.0", :group => [:development, :test]
17
17
  gem "rake-compiler", "~>0.9.2", :group => [:development, :test]
18
18
  gem "rake-compiler-dock", "~>0.5.1", :group => [:development, :test]
19
- gem "racc", ">=1.4.6", :group => [:development, :test], :platform => :ruby
20
- gem "rexical", ">=1.0.5", :group => [:development, :test], :platform => :ruby
19
+ gem "racc", "~>1.4.14", :group => [:development, :test], :platform => :ruby
20
+ gem "rexical", "~>1.0.5", :group => [:development, :test], :platform => :ruby
21
21
  gem "hoe", "~>3.14", :group => [:development, :test]
22
22
 
23
23
  # vim: syntax=ruby
data/Manifest.txt CHANGED
@@ -319,7 +319,6 @@ test/test_css_cache.rb
319
319
  test/test_encoding_handler.rb
320
320
  test/test_memory_leak.rb
321
321
  test/test_nokogiri.rb
322
- test/test_reader.rb
323
322
  test/test_soap4r_sax.rb
324
323
  test/test_xslt_transforms.rb
325
324
  test/xml/node/test_save_options.rb
@@ -351,6 +350,7 @@ test/xml/test_node_reparenting.rb
351
350
  test/xml/test_node_set.rb
352
351
  test/xml/test_parse_options.rb
353
352
  test/xml/test_processing_instruction.rb
353
+ test/xml/test_reader.rb
354
354
  test/xml/test_reader_encoding.rb
355
355
  test/xml/test_relax_ng.rb
356
356
  test/xml/test_schema.rb
data/README.md CHANGED
@@ -22,9 +22,6 @@ Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser. Among
22
22
  Nokogiri's many features is the ability to search documents via XPath
23
23
  or CSS3 selectors.
24
24
 
25
- XML is like violence - if it doesn’t solve your problems, you are not
26
- using enough of it.
27
-
28
25
 
29
26
  ## Features
30
27
 
data/Rakefile CHANGED
@@ -8,7 +8,6 @@ Hoe.plugin :debugging
8
8
  Hoe.plugin :git
9
9
  Hoe.plugin :gemspec
10
10
  Hoe.plugin :bundler
11
- Hoe.add_include_dirs '.'
12
11
 
13
12
  GENERATED_PARSER = "lib/nokogiri/css/parser.rb"
14
13
  GENERATED_TOKENIZER = "lib/nokogiri/css/tokenizer.rb"
@@ -134,16 +133,16 @@ HOE = Hoe.spec 'nokogiri' do
134
133
  end
135
134
 
136
135
  self.extra_dev_deps += [
137
- ["hoe-bundler", ">= 1.1"],
136
+ ["hoe-bundler", "~> 1.2.0"],
138
137
  ["hoe-debugging", "~> 1.2.1"],
139
- ["hoe-gemspec", ">= 1.0"],
140
- ["hoe-git", ">= 1.4"],
141
- ["minitest", "~> 2.2.2"],
142
- ["rake", ">= 0.9"],
138
+ ["hoe-gemspec", "~> 1.0.0"],
139
+ ["hoe-git", "~> 1.6.0"],
140
+ ["minitest", "~> 5.8.4"],
141
+ ["rake", "~> 10.5.0"],
143
142
  ["rake-compiler", "~> 0.9.2"],
144
143
  ["rake-compiler-dock", "~> 0.5.1"],
145
- ["racc", ">= 1.4.6"],
146
- ["rexical", ">= 1.0.5"]
144
+ ["racc", "~> 1.4.14"],
145
+ ["rexical", "~> 1.0.5"]
147
146
  ]
148
147
 
149
148
  if java?
@@ -207,7 +206,7 @@ else
207
206
 
208
207
  task gem_build_path do
209
208
  %w[libxml2 libxslt].each do |lib|
210
- version = dependencies[lib]
209
+ version = dependencies[lib]["version"]
211
210
  archive = File.join("ports", "archives", "#{lib}-#{version}.tar.gz")
212
211
  add_file_to_gem archive
213
212
  patchesdir = File.join("patches", lib)
@@ -232,7 +231,7 @@ else
232
231
  ext.cross_platform = CROSS_RUBIES.map(&:platform).uniq
233
232
  ext.cross_config_options << "--enable-cross-build"
234
233
  ext.cross_compiling do |spec|
235
- libs = dependencies.map { |name, version| "#{name}-#{version}" }.join(', ')
234
+ libs = dependencies.map { |name, dep| "#{name}-#{dep["version"]}" }.join(', ')
236
235
 
237
236
  spec.required_ruby_version = [
238
237
  '>= 1.9.2',
@@ -293,7 +292,7 @@ task :debug do
293
292
  ENV['CFLAGS'] += " -DDEBUG"
294
293
  end
295
294
 
296
- require 'tasks/test'
295
+ require File.join File.dirname(__FILE__), 'tasks/test'
297
296
 
298
297
  task :java_debug do
299
298
  ENV['JRUBY_OPTS'] = "#{ENV['JRUBY_OPTS']} --debug --dev"
data/dependencies.yml CHANGED
@@ -1,4 +1,29 @@
1
- libxml2: "2.9.3"
2
- libxslt: "1.1.28"
3
- zlib: "1.2.8"
4
- libiconv: "1.14"
1
+ libxml2:
2
+ version: "2.9.4"
3
+ md5: "ae249165c173b1ff386ee8ad676815f5" # manually confirmed via `gpg --verify`
4
+ # gpg: Signature made Mon 23 May 2016 04:02:13 AM EDT using DSA key ID DE95BC1F
5
+ # gpg: Good signature from "Daniel Veillard (Red Hat work email) <veillard@redhat.com>"
6
+ # gpg: aka "Daniel Veillard <Daniel.Veillard@w3.org>"
7
+ # gpg: WARNING: This key is not certified with a trusted signature!
8
+ # gpg: There is no indication that the signature belongs to the owner.
9
+ # Primary key fingerprint: C744 15BA 7C9C 7F78 F02E 1DC3 4606 B8A5 DE95 BC1F
10
+
11
+ libxslt:
12
+ version: "1.1.29"
13
+ md5: "a129d3c44c022de3b9dcf6d6f288d72e"
14
+ # gpg: Signature made Mon 23 May 2016 09:58:52 PM EDT using DSA key ID DE95BC1F
15
+ # gpg: Good signature from "Daniel Veillard (Red Hat work email) <veillard@redhat.com>"
16
+ # gpg: aka "Daniel Veillard <Daniel.Veillard@w3.org>"
17
+ # gpg: WARNING: This key is not certified with a trusted signature!
18
+ # gpg: There is no indication that the signature belongs to the owner.
19
+ # Primary key fingerprint: C744 15BA 7C9C 7F78 F02E 1DC3 4606 B8A5 DE95 BC1F
20
+
21
+ zlib:
22
+ version: "1.2.8"
23
+ md5: "44d667c142d7cda120332623eab69f40"
24
+
25
+ libiconv:
26
+ version: "1.14"
27
+ md5: "e34509b1623cec449dfeb73d7ce9c6c6"
28
+ # gpg: Signature made Sun 07 Aug 2011 01:58:18 PM EDT using DSA key ID F059B1D1
29
+ # gpg: BAD signature from "Bruno Haible (Open Source Development) <bruno@clisp.org>"
@@ -8,6 +8,42 @@ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
8
8
  #
9
9
  # functions
10
10
  #
11
+ def windows?
12
+ RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
13
+ end
14
+
15
+ def solaris?
16
+ RbConfig::CONFIG['target_os'] =~ /solaris/
17
+ end
18
+
19
+ def darwin?
20
+ RbConfig::CONFIG['target_os'] =~ /darwin/
21
+ end
22
+
23
+ def nix?
24
+ ! (windows? || solaris? || darwin?)
25
+ end
26
+
27
+ def sh_export_path path
28
+ # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
29
+ # as a $PATH separator, we need to convert windows paths from
30
+ #
31
+ # C:/path/to/foo
32
+ #
33
+ # to
34
+ #
35
+ # /C/path/to/foo
36
+ #
37
+ # which is sh-compatible, in order to find things properly during
38
+ # configuration
39
+ if windows?
40
+ match = Regexp.new("^([A-Z]):(/.*)").match(path)
41
+ if match && match.length == 3
42
+ return File.join("/", match[1], match[2])
43
+ end
44
+ end
45
+ path
46
+ end
11
47
 
12
48
  def do_help
13
49
  print <<HELP
@@ -364,7 +400,10 @@ when arg_config('--clean')
364
400
  end
365
401
 
366
402
  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
403
+ # use same c compiler for libxml and libxslt
404
+ ENV['CC'] = RbConfig::MAKEFILE_CONFIG['CC']
367
405
 
406
+ # TODO: deprecate MacRuby: https://github.com/sparklemotion/nokogiri/issues/1474
368
407
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
369
408
  $LIBRUBYARG_STATIC.gsub!(/-static/, '')
370
409
  end
@@ -374,17 +413,20 @@ $LIBS << " #{ENV["LIBS"]}"
374
413
  # Read CFLAGS from ENV and make sure compiling works.
375
414
  add_cflags(ENV["CFLAGS"])
376
415
 
377
- case RbConfig::CONFIG['target_os']
378
- when 'mingw32', /mswin/
379
- windows_p = true
416
+ if windows?
380
417
  $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
381
- when /solaris/
418
+ end
419
+
420
+ if solaris?
382
421
  $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
383
- when /darwin/
384
- darwin_p = true
422
+ end
423
+
424
+ if darwin?
385
425
  # Let Apple LLVM/clang 5.1 ignore unknown compiler flags
386
426
  add_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future")
387
- else
427
+ end
428
+
429
+ if nix?
388
430
  $CFLAGS << " -g -DXP_UNIX"
389
431
  end
390
432
 
@@ -436,9 +478,12 @@ else
436
478
  dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
437
479
 
438
480
  cross_build_p = enable_config("cross-build")
439
- if cross_build_p || windows_p
440
- zlib_recipe = process_recipe("zlib", dependencies["zlib"], static_p, cross_build_p) do |recipe|
441
- recipe.files = ["http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz"]
481
+ if cross_build_p || windows?
482
+ zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
483
+ recipe.files = [{
484
+ url: "http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz",
485
+ md5: dependencies["zlib"]["md5"]
486
+ }]
442
487
  class << recipe
443
488
  attr_accessor :cross_build_p
444
489
 
@@ -472,8 +517,11 @@ else
472
517
  recipe.cross_build_p = cross_build_p
473
518
  end
474
519
 
475
- libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"], static_p, cross_build_p) do |recipe|
476
- recipe.files = ["http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz"]
520
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
521
+ recipe.files = [{
522
+ url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
523
+ md5: dependencies["libiconv"]["md5"]
524
+ }]
477
525
  recipe.configure_options += [
478
526
  "CPPFLAGS=-Wall",
479
527
  "CFLAGS=-O2 -g",
@@ -482,7 +530,7 @@ else
482
530
  ]
483
531
  end
484
532
  else
485
- if darwin_p && !have_header('iconv.h')
533
+ if darwin? && !have_header('iconv.h')
486
534
  abort <<'EOM'.chomp
487
535
  -----
488
536
  The file "iconv.h" is missing in your build environment,
@@ -498,17 +546,21 @@ EOM
498
546
  end
499
547
  end
500
548
 
501
- unless windows_p
549
+ unless windows?
502
550
  preserving_globals {
503
551
  have_library('z', 'gzdopen', 'zlib.h')
504
552
  } or abort 'zlib is missing; necessary for building libxml2'
505
553
  end
506
554
 
507
- libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"], static_p, cross_build_p) do |recipe|
508
- recipe.files = ["http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz"]
555
+ libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
556
+ recipe.files = [{
557
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
558
+ md5: dependencies["libxml2"]["md5"]
559
+ }]
509
560
  recipe.configure_options += [
510
561
  "--without-python",
511
562
  "--without-readline",
563
+ *(zlib_recipe ? ["--with-zlib=#{zlib_recipe.path}", "CFLAGS=-I#{zlib_recipe.path}/include"] : []),
512
564
  *(libiconv_recipe ? "--with-iconv=#{libiconv_recipe.path}" : iconv_configure_flags),
513
565
  "--with-c14n",
514
566
  "--with-debug",
@@ -516,13 +568,16 @@ EOM
516
568
  ]
517
569
  end
518
570
 
519
- libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"], static_p, cross_build_p) do |recipe|
520
- recipe.files = ["http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz"]
571
+ libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
572
+ recipe.files = [{
573
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
574
+ md5: dependencies["libxslt"]["md5"]
575
+ }]
521
576
  recipe.configure_options += [
522
577
  "--without-python",
523
578
  "--without-crypto",
524
579
  "--with-debug",
525
- "--with-libxml-prefix=#{libxml2_recipe.path}"
580
+ "--with-libxml-prefix=#{sh_export_path(libxml2_recipe.path)}"
526
581
  ]
527
582
  end
528
583
 
@@ -35,13 +35,13 @@ static void relink_namespace(xmlNodePtr reparented)
35
35
  xmlNsPtr ns;
36
36
 
37
37
  if (reparented->type != XML_ATTRIBUTE_NODE &&
38
- reparented->type != XML_ELEMENT_NODE) return;
38
+ reparented->type != XML_ELEMENT_NODE) { return; }
39
39
 
40
40
  if (reparented->ns == NULL || reparented->ns->prefix == NULL) {
41
41
  name = xmlSplitQName2(reparented->name, &prefix);
42
42
 
43
43
  if(reparented->type == XML_ATTRIBUTE_NODE) {
44
- if (prefix == NULL || strcmp((char*)prefix, XMLNS_PREFIX) == 0) return;
44
+ if (prefix == NULL || strcmp((char*)prefix, XMLNS_PREFIX) == 0) { return; }
45
45
  }
46
46
 
47
47
  ns = xmlSearchNs(reparented->doc, reparented, prefix);
@@ -57,18 +57,19 @@ static void relink_namespace(xmlNodePtr reparented)
57
57
  }
58
58
 
59
59
  /* Avoid segv when relinking against unlinked nodes. */
60
- if (reparented->type != XML_ELEMENT_NODE || !reparented->parent) return;
60
+ if (reparented->type != XML_ELEMENT_NODE || !reparented->parent) { return; }
61
61
 
62
62
  /* Make sure that our reparented node has the correct namespaces */
63
- if(!reparented->ns && reparented->doc != (xmlDocPtr)reparented->parent)
63
+ if (!reparented->ns && reparented->doc != (xmlDocPtr)reparented->parent) {
64
64
  xmlSetNs(reparented, reparented->parent->ns);
65
+ }
65
66
 
66
67
  /* Search our parents for an existing definition */
67
- if(reparented->nsDef) {
68
+ if (reparented->nsDef) {
68
69
  xmlNsPtr curr = reparented->nsDef;
69
70
  xmlNsPtr prev = NULL;
70
71
 
71
- while(curr) {
72
+ while (curr) {
72
73
  xmlNsPtr ns = xmlSearchNsByHref(
73
74
  reparented->doc,
74
75
  reparented->parent,
@@ -76,7 +77,7 @@ static void relink_namespace(xmlNodePtr reparented)
76
77
  );
77
78
  /* If we find the namespace is already declared, remove it from this
78
79
  * definition list. */
79
- if(ns && ns != curr) {
80
+ if (ns && ns != curr && xmlStrEqual(ns->prefix, curr->prefix)) {
80
81
  if (prev) {
81
82
  prev->next = curr->next;
82
83
  } else {
@@ -92,12 +93,12 @@ static void relink_namespace(xmlNodePtr reparented)
92
93
 
93
94
  /* Only walk all children if there actually is a namespace we need to */
94
95
  /* reparent. */
95
- if(NULL == reparented->ns) return;
96
+ if (NULL == reparented->ns) { return; }
96
97
 
97
98
  /* When a node gets reparented, walk it's children to make sure that */
98
99
  /* their namespaces are reparented as well. */
99
100
  child = reparented->children;
100
- while(NULL != child) {
101
+ while (NULL != child) {
101
102
  relink_namespace(child);
102
103
  child = child->next;
103
104
  }
@@ -140,6 +141,7 @@ static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_rep
140
141
  {
141
142
  VALUE reparented_obj ;
142
143
  xmlNodePtr reparentee, pivot, reparented, next_text, new_next_text, parent ;
144
+ int original_ns_prefix_is_default = 0 ;
143
145
 
144
146
  if(!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode))
145
147
  rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
@@ -250,10 +252,21 @@ ok:
250
252
  */
251
253
  reparentee->_private = NULL ;
252
254
  }
255
+
256
+ if (reparentee->ns != NULL && reparentee->ns->prefix == NULL) {
257
+ original_ns_prefix_is_default = 1;
258
+ }
259
+
253
260
  nokogiri_root_node(reparentee);
261
+
254
262
  if (!(reparentee = xmlDocCopyNode(reparentee, pivot->doc, 1))) {
255
263
  rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
256
264
  }
265
+
266
+ if (original_ns_prefix_is_default && reparentee->ns != NULL && reparentee->ns->prefix != NULL) {
267
+ /* issue #391, where new node's prefix may become the string "default" */
268
+ reparentee->ns->prefix = NULL;
269
+ }
257
270
  }
258
271
 
259
272
  if (prf != xmlAddPrevSibling && prf != xmlAddNextSibling