Merge branch 'master' into 2681-new-inactive-user-notification
[arvados.git] / services / api / app / controllers / arvados / v1 / collections_controller.rb
index 2844cb4c7a0f0afc8bcf40c5b3fb0b9f9b9d53b2..6c9d41e3f1f468c2a49a9b7f018923668acd63f1 100644 (file)
@@ -1,5 +1,3 @@
-require 'locator'
-
 class Arvados::V1::CollectionsController < ApplicationController
   def create
     # Collections are owned by system_user. Creating a collection has
@@ -24,8 +22,8 @@ class Arvados::V1::CollectionsController < ApplicationController
     }
     resource_attrs[:manifest_text].lines.each do |entry|
       entry.split[1..-1].each do |tok|
-        # TODO(twp): fail the request if this match fails.
-        # Add in Phase 4 (see #2755)
+        # TODO(twp): in Phase 4, fail the request if the locator
+        # lacks a permission signature. (see #2755)
         loc = Locator.parse(tok)
         if loc and loc.signature
           if !api_token
@@ -44,12 +42,13 @@ class Arvados::V1::CollectionsController < ApplicationController
 
     # Remove any permission signatures from the manifest.
     resource_attrs[:manifest_text]
-      .gsub!(/[[:xdigit:]]{32}(\+[[:digit:]]+)?(\+\S+)/) { |word|
+      .gsub!(/ [[:xdigit:]]{32}(\+[[:digit:]]+)?(\+\S+)/) { |word|
+      word.strip!
       loc = Locator.parse(word)
       if loc
-        loc.without_signature.to_s
+        " " + loc.without_signature.to_s
       else
-        word
+        " " + word
       end
     }
 
@@ -95,12 +94,13 @@ class Arvados::V1::CollectionsController < ApplicationController
         ttl: Rails.configuration.blob_signing_ttl,
       }
       @object[:manifest_text]
-        .gsub!(/[[:xdigit:]]{32}(\+[[:digit:]]+)?(\+\S+)/) { |word|
+        .gsub!(/ [[:xdigit:]]{32}(\+[[:digit:]]+)?(\+\S+)/) { |word|
+        word.strip!
         loc = Locator.parse(word)
         if loc
-          Blob.sign_locator(word, signing_opts)
+          " " + Blob.sign_locator(word, signing_opts)
         else
-          word
+          " " + word
         end
       }
     end