From 6caa01e337f5c6a3cd141304a920781a29825452 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <[email protected]>
Date: Fri, 2 Sep 2016 10:37:35 +0200
Subject: Fix replacing with an empty document by update() method

---
 ...-652-Fix-legacy-update-for-empty-document.patch | 59 ++++++++++++++++++++++
 perl-MongoDB.spec                                  | 10 +++-
 2 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 
MongoDB-v1.2.3-PERL-652-Fix-legacy-update-for-empty-document.patch

diff --git a/MongoDB-v1.2.3-PERL-652-Fix-legacy-update-for-empty-document.patch 
b/MongoDB-v1.2.3-PERL-652-Fix-legacy-update-for-empty-document.patch
new file mode 100644
index 0000000..6c3c0a2
--- /dev/null
+++ b/MongoDB-v1.2.3-PERL-652-Fix-legacy-update-for-empty-document.patch
@@ -0,0 +1,59 @@
+From 81f67bea6d859740f3998fc3e1c1ceb36c91244a Mon Sep 17 00:00:00 2001
+From: David Golden <[email protected]>
+Date: Mon, 22 Aug 2016 13:53:00 -0400
+Subject: [PATCH] PERL-652 Fix legacy update for empty document
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Petr Pisar: Ported to 1.2.3.
+
+Signed-off-by: Petr Písař <[email protected]>
+---
+ lib/MongoDB/Collection.pm | 5 +++--
+ t/deprecated/collection.t | 8 ++++++++
+ 2 files changed, 11 insertions(+), 2 deletions(-)
+
+diff --git a/lib/MongoDB/Collection.pm b/lib/MongoDB/Collection.pm
+index 0e3b720..3b4583a 100644
+--- a/lib/MongoDB/Collection.pm
++++ b/lib/MongoDB/Collection.pm
+@@ -1596,6 +1596,7 @@ my $legacy_update_args;
+ sub update {
+     my ( $self, $query, $object, $opts ) = @_;
+     $opts ||= {};
++    $object ||= {};
+ 
+     if ( exists $opts->{multiple} ) {
+         if ( exists( $opts->{multi} ) && !!$opts->{multi} ne 
!!$opts->{multiple} ) {
+@@ -1615,8 +1616,8 @@ sub update {
+     );
+     $fk = defined($fk) ? substr($fk,0,1) : '';
+ 
+-    my $op_char = eval { $self->bson_codec->op_char } || '';
+-    my $is_replace = $fk ne '$' && $fk ne $op_char;
++    my $op_char = eval { $self->bson_codec->op_char } || '$';
++    my $is_replace = $fk ne $op_char;
+ 
+     my $op = MongoDB::Op::_Update->_new(
+         filter => $query  || {},
+diff --git a/t/deprecated/collection.t b/t/deprecated/collection.t
+index 605775d..3902440 100644
+--- a/t/deprecated/collection.t
++++ b/t/deprecated/collection.t
+@@ -628,4 +628,12 @@ for my $criteria ( $js_str, $js_obj ) {
+     };
+ }
+ 
++subtest "empty update" => sub {
++    $coll->drop;
++    my $id = $coll->insert( { a => 1, b => 1 } );
++    $coll->update( { a => 1 }, {} );
++    is( $coll->count( { _id => $id } ), 1, "document _id field not modified" 
);
++    is( $coll->count( { a => 1 } ), 0, "document data modified" );
++};
++
+ done_testing;
+-- 
+2.5.5
+
diff --git a/perl-MongoDB.spec b/perl-MongoDB.spec
index 8f617b2..bf44765 100644
--- a/perl-MongoDB.spec
+++ b/perl-MongoDB.spec
@@ -1,6 +1,6 @@
 Name:           perl-MongoDB
 Version:        1.2.3
-Release:        2%{?dist}
+Release:        3%{?dist}
 Summary:        A MongoDB Driver for Perl
 ## Installed:
 # lib/MongoDB/_Link.pm:             ASL 2.0 and (GPL+ or Artistic)
@@ -20,6 +20,9 @@ Patch0:         
MongoDB-v1.2.2-Use-system-libbson-library-if-possible.patch
 # Fix authentication against hidden or uninitialized replica set members,
 # in upstream 1.4.4, <https://jira.mongodb.org/browse/PERL-647>
 Patch1:         
MongoDB-1.2.3-PERL-647-Authenticate-always-to-topology-type-Single.patch
+# Fix replacing with an empty document by update() method, in upstream 1.4.5,
+# <https://jira.mongodb.org/browse/PERL-652>
+Patch2:         
MongoDB-v1.2.3-PERL-652-Fix-legacy-update-for-empty-document.patch
 # Build
 BuildRequires:  coreutils
 BuildRequires:  findutils
@@ -138,6 +141,7 @@ The perl database access module for MongoDB.
 # Unbundle libbson
 %patch0 -p1
 %patch1 -p1
+%patch2 -p1
 rm -r bson
 sed -i -e '/^bson\//d' MANIFEST
 # Remove bundled modules
@@ -187,6 +191,10 @@ exit $test_rc
 %{_mandir}/man3/*
 
 %changelog
+* Fri Sep 02 2016 Petr Pisar <[email protected]> - 1.2.3-3
+- Fix replacing with an empty document by update() method
+  (upstream bug PERL-652)
+
 * Tue Aug 30 2016 Petr Pisar <[email protected]> - 1.2.3-2
 - Fix authentication against hidden or uninitialized replica set members
   (upstream bug PERL-647)
-- 
cgit v0.12


        
http://pkgs.fedoraproject.org/cgit/perl-MongoDB.git/commit/?h=f24&id=6caa01e337f5c6a3cd141304a920781a29825452
--
Fedora Extras Perl SIG
http://www.fedoraproject.org/wiki/Extras/SIGs/Perl
perl-devel mailing list
[email protected]
https://lists.fedoraproject.org/admin/lists/[email protected]

Reply via email to