Permalink
Browse files

normalize "/a//" to "a" (affects Morpheus::Defaults/Overrides etc.)

  • Loading branch information...
1 parent 69eea38 commit 135cf5a06ab29598d7dd7fcc058b67704c877b3a @druxa committed Dec 16, 2010
Showing with 33 additions and 4 deletions.
  1. +1 −1 .gitignore
  2. +1 −0 Changes
  3. +6 −0 debian/changelog
  4. +1 −1 dist.ini
  5. +1 −2 lib/Morpheus/Utils.pm
  6. +23 −0 t/normalize.t
View
@@ -1,4 +1,4 @@
-/.debuild
+/debuild
/Morpheus-*
/.build
/libmorpheus-perl*
View
@@ -1,6 +1,7 @@
Revision history for Morpheus
{{$NEXT}}
+ * normalize "/a//" to "a" (affects Morpheus::Defaults/Overrides etc.)
0.34 Sat Nov 13, 2010
* call dh_perldeps when possible
View
@@ -1,3 +1,9 @@
+libmorpheus-perl (0.35) stable; urgency=low
+
+ * normalize "/a//" to "a" (affects Morpheus::Defaults/Overrides etc.)
+
+ -- Andrei Mishchenko <druxa@yandex-team.ru> Thu, 16 Dec 2010 17:12:07 +0300
+
libmorpheus-perl (0.34) stable; urgency=low
* get rid of Sys::Hostname::Long and parent dependencies
View
@@ -1,5 +1,5 @@
name = Morpheus
-version = 0.34
+version = 0.35
author = Andrei Mishchenko <druxa@yandex-team.ru>
license = Perl_5
copyright_holder = Yandex LLC
View
@@ -20,8 +20,7 @@ sub normalize ($) {
my $result = { %$data };
for my $key ( keys %$data) {
my @keys = @{key($key)};
- next if @keys == 1;
-
+ next if @keys == 1 and $keys[0] eq $key; # "/a//" -> "a"
my $value = delete $result->{$key};
my $p = my $patch = {};
$p = $p->{$_} = {} for splice @keys, 0, -1;
View
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+package Morpheus::Test::Normalize;
+
+use strict;
+use warnings;
+
+use base qw(Test::Class);
+use Test::More;
+use Symbol;
+
+use lib 'lib';
+
+use Morpheus::Utils qw(normalize);
+
+sub general : Test(4) {
+
+ is_deeply(normalize({"a/b" => 1}), {a=>{b=>1}}, "basic test");
+ is_deeply(normalize({"/a/b//" => 1}), {a=>{b=>1}}, "extra slashes");
+ is_deeply(normalize({"/a//" => 1}), {a=>1}, "extra slashes in simple key");
+ is_deeply(normalize({a => {b => 1}, "a/c" => 2, "/a/" => {d => 3}}), {a=>{b => 1, c => 2, d => 3}}, "normalize merges");
+}
+
+__PACKAGE__->new->runtests;

0 comments on commit 135cf5a

Please sign in to comment.