+1

On Fri, Jul 16, 2010 at 3:21 PM, Jesse Wolfe <[email protected]> wrote:
> Puppet allows resource titles to contain newlines. We recently
> introduced several regexps that were failing on resources with multiline
> titles.
>
> Signed-off-by: Jesse Wolfe <[email protected]>
> ---
>  lib/puppet/resource/catalog.rb     |    2 +-
>  lib/puppet/type.rb                 |    2 +-
>  lib/puppet/type/file.rb            |    2 +-
>  spec/unit/resource/catalog_spec.rb |    9 +++++++++
>  spec/unit/type/file_spec.rb        |   14 ++++++++++++++
>  spec/unit/type_spec.rb             |   21 +++++++++++++++++++++
>  6 files changed, 47 insertions(+), 3 deletions(-)
>
> diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
> index d163fc1..4ac99ee 100644
> --- a/lib/puppet/resource/catalog.rb
> +++ b/lib/puppet/resource/catalog.rb
> @@ -57,7 +57,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
>   end
>
>   def title_key_for_ref( ref )
> -    ref =~ /^(.+)\[(.*)\]/
> +    ref =~ /^(.+)\[(.*)\]/m
>     [$1, $2]
>   end
>
> diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
> index d0fea97..627271f 100644
> --- a/lib/puppet/type.rb
> +++ b/lib/puppet/type.rb
> @@ -193,7 +193,7 @@ class Type
>     when 0; []
>     when 1;
>       identity = lambda {|x| x}
> -      [ [ /(.*)/, [ [key_attributes.first, identity ] ] ] ]
> +      [ [ /(.*)/m, [ [key_attributes.first, identity ] ] ] ]
>     else
>       raise Puppet::DevError,"you must specify title patterns when there are 
> two or more key attributes"
>     end
> diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
> index 195e8c8..71f2756 100644
> --- a/lib/puppet/type/file.rb
> +++ b/lib/puppet/type/file.rb
> @@ -25,7 +25,7 @@ Puppet::Type.newtype(:file) do
>     native resource to support what you are doing."
>
>   def self.title_patterns
> -    [ [ /^(.*?)\/?$/, [ [ :path, lambda{|x| x} ] ] ] ]
> +    [ [ /^(.*?)\/*\Z/m, [ [ :path, lambda{|x| x} ] ] ] ]
>   end
>
>   newparam(:path) do
> diff --git a/spec/unit/resource/catalog_spec.rb 
> b/spec/unit/resource/catalog_spec.rb
> index b6f96f0..10cff91 100755
> --- a/spec/unit/resource/catalog_spec.rb
> +++ b/spec/unit/resource/catalog_spec.rb
> @@ -1066,4 +1066,13 @@ describe Puppet::Resource::Catalog, "when converting 
> from pson" do
>
>     lambda { PSON.parse @pson.to_pson }.should raise_error(ArgumentError)
>   end
> +
> +  describe "#title_key_for_ref" do
> +    it "should parse a resource ref string into a pair" do
> +     �[email protected]_key_for_ref("Title[name]").should == ["Title", 
> "name"]
> +    end
> +    it "should parse a resource ref string into a pair, even if there's a 
> newline inside the name" do
> +     �[email protected]_key_for_ref("Title[na\nme]").should == ["Title", 
> "na\nme"]
> +    end
> +  end
>  end
> diff --git a/spec/unit/type/file_spec.rb b/spec/unit/type/file_spec.rb
> index 845bf3d..7d93dfd 100755
> --- a/spec/unit/type/file_spec.rb
> +++ b/spec/unit/type/file_spec.rb
> @@ -1053,4 +1053,18 @@ describe Puppet::Type.type(:file) do
>       file.retrieve
>     end
>   end
> +
> +  describe ".title_patterns" do
> +    before do
> +     �...@type_class = Puppet::Type.type(:file)
> +    end
> +
> +    it "should have a regexp that captures the entire string, except for a 
> terminating slash" do
> +      patterns = @type_class.title_patterns
> +      string = "abc/\n\tdef/"
> +      patterns[0][0] =~ string
> +      $1.should == "abc/\n\tdef"
> +    end
> +  end
> +
>  end
> diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb
> index 683529d..71d415d 100755
> --- a/spec/unit/type_spec.rb
> +++ b/spec/unit/type_spec.rb
> @@ -406,6 +406,27 @@ describe Puppet::Type do
>     end
>   end
>
> +  describe ".title_patterns" do
> +    describe "when there's one namevar" do
> +      before do
> +       �...@type_class = Puppet::Type.type(:notify)
> +       �...@type_class.stubs(:key_attributes).returns([:one])
> +      end
> +
> +      it "should have a default pattern for when there's one namevar" do
> +        patterns = @type_class.title_patterns
> +        patterns.length.should == 1
> +        patterns[0].length.should == 2
> +      end
> +
> +      it "should have a regexp that captures the entire string" do
> +        patterns = @type_class.title_patterns
> +        string = "abc\n\tdef"
> +        patterns[0][0] =~ string
> +        $1.should == "abc\n\tdef"
> +      end
> +    end
> +  end
>
>   describe "when in a catalog" do
>     before do
> --
> 1.7.0.4
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/puppet-dev?hl=en.
>
>



-- 
-----------------------------------------------------------
The power of accurate observation is
commonly called cynicism by those
who have not got it.  ~George Bernard Shaw
------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to