From 429e214477b46eb0a73f971d8f325be3aeb3d196 Mon Sep 17 00:00:00 2001 From: Michael Burrows Date: Fri, 10 Apr 2009 11:58:49 +0100 Subject: [PATCH] Fix URI template operators 'prefix', 'suffix' and 'list' to return the empty string for undefined variables. As per draft 3 of the URI template spec, made the the 'prefix', 'suffix' and 'list' to return the empty string for undefined variables. Previously, 'prefix' and 'suffix' returned the arg regardless and 'list' raised an exception. Added tests. Ideally the next draft of the spec would include examples equivalent to these. --- lib/addressable/uri.rb | 7 ++++--- spec/addressable/uri_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index 4b7f5604..927c1ddd 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -461,7 +461,7 @@ def self.expand_prefix_operator(argument, variables, mapping) value = mapping[variables.first] if value.kind_of?(Array) (value.map { |list_value| argument + list_value }).join("") - else + elsif value argument + value.to_s end end @@ -483,7 +483,7 @@ def self.expand_suffix_operator(argument, variables, mapping) value = mapping[variables.first] if value.kind_of?(Array) (value.map { |list_value| list_value + argument }).join("") - else + elsif value value.to_s + argument end end @@ -526,7 +526,8 @@ def self.expand_list_operator(argument, variables, mapping) raise InvalidTemplateOperatorError, "Template operator 'list' takes exactly one variable." end - mapping[variables.first].join(argument) + values = mapping[variables.first] + values.join(argument) if values end class <