From 91c7597d7bff612e360dcf36cfdb0616dfcfb925 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Wed, 17 Jul 2019 01:51:46 +0300 Subject: [PATCH 1/9] The bug description is not valid anymore --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index c5c0c47..eaabd62 100644 --- a/README.md +++ b/README.md @@ -116,10 +116,3 @@ if $result { say "Parsing error"; } ``` - -BUGS: - -Grammar for basic attributes values use just \N* pattern so some -invalid values (eg. binary numbers with invalid format) are accepted. -If database don't allow such values they will be rejected during -import. From 0bac414c307a3406938fe57c8bb35078b411190c Mon Sep 17 00:00:00 2001 From: Altai-man Date: Thu, 18 Jul 2019 00:52:09 +0300 Subject: [PATCH 2/9] Indicate that DN is base64 --- lib/Text/LDIF/Actions.pm6 | 2 +- t/01.t | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Text/LDIF/Actions.pm6 b/lib/Text/LDIF/Actions.pm6 index b080cf1..0923016 100644 --- a/lib/Text/LDIF/Actions.pm6 +++ b/lib/Text/LDIF/Actions.pm6 @@ -41,7 +41,7 @@ class Text::LDIF::Actions { with $ { make .Str; } orwith $ { - make .Str; + make Pair.new('base64', .Str); } } diff --git a/t/01.t b/t/01.t index 5ccfc87..2b1cd09 100644 --- a/t/01.t +++ b/t/01.t @@ -39,6 +39,7 @@ check-parses '3', -> $r { check-parses '4', -> $r { my $ou = $r[0]; + is-deeply $r[0], Pair.new('base64', 'b3U95Za25qWt6YOoLG89QWlyaXVz'), 'Base64 is expressed as Pair'; is-deeply $ou{''}, Pair.new('base64', '5Za25qWt6YOo'), "Option-less attribute"; is-deeply $ou, 'Sales', "Simple option attribute"; is-deeply $ou, Pair.new('base64', '5Za25qWt6YOo'), 'BASE64 option attribute'; From af24b3f55e664eb884a6d838c2cde0be2c479e17 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Thu, 18 Jul 2019 00:54:36 +0300 Subject: [PATCH 3/9] Update META6.json --- META6.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/META6.json b/META6.json index 9385d63..f35245c 100644 --- a/META6.json +++ b/META6.json @@ -1,7 +1,7 @@ { "name": "Text::LDIF", "description": "Pure Perl6 LDIF file parser", - "version": "1.0", + "version": "1.0.1", "perl": "6.c", "auth": "github:slunski", "depends": [], @@ -17,4 +17,4 @@ "source-url": "git://github.com/slunski/perl6-text-ldif.git", "author": "Sylwester Lunski", "repo-type": "git" -} \ No newline at end of file +} From 17b392f6950eafc6faa8dc7c1b33f475f60d7967 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sat, 27 Jul 2019 19:07:36 +0300 Subject: [PATCH 4/9] Be more explicit --- lib/Text/LDIF/Actions.pm6 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Text/LDIF/Actions.pm6 b/lib/Text/LDIF/Actions.pm6 index 0923016..2d74c2e 100644 --- a/lib/Text/LDIF/Actions.pm6 +++ b/lib/Text/LDIF/Actions.pm6 @@ -124,9 +124,19 @@ class Text::LDIF::Actions { } method change-moddn($/) { - my $newrdn = ~($ // $); + my $newrdn; + with $ { + $newrdn = ~$_; + } orwith $ { + $newrdn = base64 => ~$_; + } my $delete-on-rdn = $ eq '1'; - my $newsuperior = $ // $; + my $newsuperior; + with $ { + $newsuperior = ~$_; + } orwith $ { + $newsuperior = base64 => ~$_; + } make Pair.new('moddn', %(:$newrdn, :$delete-on-rdn, :$newsuperior)); } } From 179e8d675b2acbad26db53fb5797d97e8c50ed17 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sat, 27 Jul 2019 19:45:38 +0300 Subject: [PATCH 5/9] Make parser result tree more explicit * Version number is exposed as Int * For list of attribute values, type is List instead of Seq * Single attributes in modifications are no longer packed into Hash --- META6.json | 4 +-- lib/Text/LDIF/Actions.pm6 | 8 ++++-- t/01.t | 52 +++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/META6.json b/META6.json index f35245c..fe3f098 100644 --- a/META6.json +++ b/META6.json @@ -1,7 +1,7 @@ { "name": "Text::LDIF", "description": "Pure Perl6 LDIF file parser", - "version": "1.0.1", + "version": "1.0.2", "perl": "6.c", "auth": "github:slunski", "depends": [], @@ -17,4 +17,4 @@ "source-url": "git://github.com/slunski/perl6-text-ldif.git", "author": "Sylwester Lunski", "repo-type": "git" -} +} \ No newline at end of file diff --git a/lib/Text/LDIF/Actions.pm6 b/lib/Text/LDIF/Actions.pm6 index 2d74c2e..b874eba 100644 --- a/lib/Text/LDIF/Actions.pm6 +++ b/lib/Text/LDIF/Actions.pm6 @@ -2,7 +2,7 @@ use v6; class Text::LDIF::Actions { method TOP($/) { - my %attrs = version => ~$[0]; + my %attrs = version => $[0].Int; with $ { %attrs = .made; @@ -28,12 +28,16 @@ class Text::LDIF::Actions { %attrs{$k} = $v[0].value; } else { if $v.map(*.key eq '').all { - %attrs{$k} = $v.map(*.value); + %attrs{$k} = $v.map(*.value).List; } else { %attrs{$k} = $v.Hash; } } } + if %attrs.elems == 1 { + # We have only single key, so return a single Pair + return %attrs.keys[0] => %attrs{%attrs.keys[0]}; + } %attrs; } diff --git a/t/01.t b/t/01.t index 2b1cd09..88da4ca 100644 --- a/t/01.t +++ b/t/01.t @@ -12,28 +12,28 @@ sub check-parses(Str $fn, &check) { } check-parses '1', -> $r { - is $r, 1, "Version is correct"; + is-deeply $r, 1, "Version is correct"; my $recs = $r; - is $recs.elems, 2, "Two entries were read"; + is-deeply $recs.elems, 2, "Two entries were read"; - is $recs[0], 'cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com', "DN is correct for first entry"; + is-deeply $recs[0], 'cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com', "DN is correct for first entry"; my $rec-attrs = $recs[0]; - is $rec-attrs, , "objectclass multi-values are concatenated"; - is $rec-attrs, 'Jensen', "sn is correct"; - is $rec-attrs, '+1 408 555 1212', 'phonenumber is read ok'; + is-deeply $rec-attrs, , "objectclass multi-values are concatenated"; + is-deeply $rec-attrs, 'Jensen', "sn is correct"; + is-deeply $rec-attrs, '+1 408 555 1212', 'phonenumber is read ok'; - is $recs[1], 'cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com', 'DN is correct for second entry'; + is-deeply $recs[1], 'cn=Bjorn Jensen, ou=Accounting, dc=airius, dc=com', 'DN is correct for second entry'; $rec-attrs = $recs[1]; - is $rec-attrs, , 'objectclass multi-values are concatenated'; + is-deeply $rec-attrs, , 'objectclass multi-values are concatenated'; } check-parses '2', -> $r { - is $r[0], 'Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions.', + is-deeply $r[0], 'Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions.', 'folded description was concatenated'; } check-parses '3', -> $r { - is $r[0], Pair.new('base64', 'V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVlIGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdGVyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQgb3V0IG1vcmUu'), + is-deeply $r[0], Pair.new('base64', 'V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVlIGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdGVyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQgb3V0IG1vcmUu'), 'base64 value is read'; } @@ -55,39 +55,39 @@ check-parses '6', -> $r { my $change = $changes[0]; is-deeply $change, 'cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com'; - is $change.key, 'add'; - is $change.value, 'Fiona Jensen'; + is-deeply $change.key, 'add'; + is-deeply $change.value, 'Fiona Jensen'; is-deeply $change.value, Pair.new('file', 'file://foo.jpg'); is-deeply $change, []; $change = $changes[1]; - is $change, 'delete'; + is-deeply $change, 'delete'; $change = $changes[2]; - is $change.key, 'moddn'; + is-deeply $change.key, 'moddn'; ok $change; - is $change, 'cn=Paula Jensen'; + is-deeply $change, 'cn=Paula Jensen'; $change = $changes[3]; - is $change.key, 'moddn'; + is-deeply $change.key, 'moddn'; nok $change; - is $change, 'ou=Product Development Accountants'; + is-deeply $change, 'ou=Product Development Accountants'; $change = $changes[4]; - is $change.key, 'modify'; - is $change[0], Pair.new('add', Pair.new('postaladdress', '123 Anystreet $ Sunnyvale, CA $ 94086')); - is $change[1], Pair.new('delete', 'description'); - is $change[2], Pair.new('replace', Pair.new('telephonenumber', ('+1 408 555 1234', '+1 408 555 5678'))); + is-deeply $change.key, 'modify'; + is-deeply $change[0], Pair.new('add', Pair.new('postaladdress', '123 Anystreet $ Sunnyvale, CA $ 94086')); + is-deeply $change[1], Pair.new('delete', 'description'); + is-deeply $change[2], Pair.new('replace', Pair.new('telephonenumber', ('+1 408 555 1234', '+1 408 555 5678'))); $change = $changes[5]; - is $change.key, 'modify'; - is $change[0], Pair.new('replace', 'postaladdress'); - is $change[1], Pair.new('delete', 'description'); + is-deeply $change.key, 'modify'; + is-deeply $change[0], Pair.new('replace', 'postaladdress'); + is-deeply $change[1], Pair.new('delete', 'description'); } check-parses '7', -> $r { - is $r[0], 'ou=Product Development, dc=airius, dc=com'; - is $r[0][0], '1.2.840.113556.1.4.805'; + is-deeply $r[0], 'ou=Product Development, dc=airius, dc=com'; + is-deeply $r[0][0], '1.2.840.113556.1.4.805'; ok $r[0][0]; } From cc7136304676e4ea83598fc97f8253a2c761f923 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sat, 27 Jul 2019 19:59:33 +0300 Subject: [PATCH 6/9] Update authorship info --- META6.json | 5 ++++- README.md | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/META6.json b/META6.json index fe3f098..9982ed7 100644 --- a/META6.json +++ b/META6.json @@ -3,6 +3,10 @@ "description": "Pure Perl6 LDIF file parser", "version": "1.0.2", "perl": "6.c", + "authors": [ + "Sylwester Lunski", + "Alexander Kiryuhin" + ], "auth": "github:slunski", "depends": [], "test-depends": [ @@ -15,6 +19,5 @@ }, "license": "Artistic-2.0", "source-url": "git://github.com/slunski/perl6-text-ldif.git", - "author": "Sylwester Lunski", "repo-type": "git" } \ No newline at end of file diff --git a/README.md b/README.md index eaabd62..4ac35ea 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,8 @@ if $result { say "Parsing error"; } ``` + +### Authors + +* The original module was developed by @slunski +* Current fork was started by @Altai-man who introduced some compatibility breaking changes From a13526804a588d7ce683f58d660723900f49dce6 Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sun, 28 Jul 2019 13:35:08 +0300 Subject: [PATCH 7/9] Update source-url --- META6.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/META6.json b/META6.json index 9982ed7..f44e707 100644 --- a/META6.json +++ b/META6.json @@ -18,6 +18,6 @@ "Text::LDIF::Grammar": "lib/Text/LDIF/Grammar.pm6" }, "license": "Artistic-2.0", - "source-url": "git://github.com/slunski/perl6-text-ldif.git", + "source-url": "git://github.com/Altai-man/perl6-text-ldif.git", "repo-type": "git" -} \ No newline at end of file +} From 7379f62af95841a351a0c0196b35c00192ad07ca Mon Sep 17 00:00:00 2001 From: Altai-man Date: Sun, 28 Jul 2019 21:41:16 +0300 Subject: [PATCH 8/9] Do not create hashes for options In fact, is a very unpractical to do so and has no strong benefits: Perl 6 handles hashes with ';' in them just fine and our previous approach was causing just more code for both parser and code that interpretes parsing results. --- lib/Text/LDIF/Actions.pm6 | 29 +++++++++-------------------- t/01.t | 12 ++++++------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/Text/LDIF/Actions.pm6 b/lib/Text/LDIF/Actions.pm6 index b874eba..774a06e 100644 --- a/lib/Text/LDIF/Actions.pm6 +++ b/lib/Text/LDIF/Actions.pm6 @@ -25,13 +25,9 @@ class Text::LDIF::Actions { my %attrs; for $attributes.kv -> $k, $v { if $v.elems == 1 { - %attrs{$k} = $v[0].value; + %attrs{$k} = $v[0]; } else { - if $v.map(*.key eq '').all { - %attrs{$k} = $v.map(*.value).List; - } else { - %attrs{$k} = $v.Hash; - } + %attrs{$k} = $v.List; } } if %attrs.elems == 1 { @@ -51,14 +47,11 @@ class Text::LDIF::Actions { method attrval-spec($/) { with $ -> $attr { - my @options; - with $attr { - @options.push($_.Str) for $_