Subject: | [PATCH] standard-compliant Slug encoding |
createEntry fails for some post names. I am using just a slight modification of the module's synopsis. The reason for the failure is that you neglect to encode the Slug header to UTF-8 like it is specified in the RFC. Attached patch fixes that.
Module versions:
Atompub: 0.3.2
XML::Atom: 0.37
libwww-perl: 5.834
URI: 1.51
Sample code exhibiting the problem.
use utf8;
use Atompub::Client qw();
my $client = Atompub::Client->new;
my $service = $client->getService('http://localhost:3000/myservice');
# testing against "MyAtom" from the Catalyst distro
my @workspaces = $service->workspaces;
my @collections = $workspaces[0]->collections;
my $collection_uri = $collections[0]->href;
my $name = 'New Post一二三';
my $entry = XML::Atom::Entry->new;
$entry->title($name);
$entry->content('Content of my post.一二三');
my $edit_uri = $client->createEntry($collection_uri, $entry, $name);
# this call will fail and return undef
print $client->res->as_string unless $client->res->is_success;
# 500 Wide character in HTTP request (bytes required)
# Content-Type: text/plain
# Client-Warning: Internal response
Subject: | 0001-standard-compliant-Slug-encoding.patch |
From c666942eecdcfab488e12f86aded0f27615437b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lars=20D=C9=AA=E1=B4=87=E1=B4=84=E1=B4=8B=E1=B4=8F=E1=B4=A1=20=E8=BF=AA=E6=8B=89=E6=96=AF?= <daxim@cpan.org>
Date: Tue, 29 Dec 2009 20:04:32 +0100
Subject: [PATCH] standard-compliant Slug encoding
---
lib/Atompub/Client.pm | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/Atompub/Client.pm b/lib/Atompub/Client.pm
index cd572e7..24160d4 100644
--- a/lib/Atompub/Client.pm
+++ b/lib/Atompub/Client.pm
@@ -8,6 +8,7 @@ use Atompub::DateTime qw(datetime);
use Atompub::MediaType qw(media_type);
use Atompub::Util qw(is_acceptable_media_type is_allowed_category);
use Digest::SHA1 qw(sha1);
+use Encode qw(encode_utf8);
use File::Slurp;
use HTTP::Status;
use MIME::Base64 qw(encode_base64);
@@ -444,7 +445,8 @@ sub munge_request {
# see 9.7.1 in RFC 5023
sub _escape {
- uri_escape(uri_escape(uri_escape(shift, "\x00-\x19"), "\x25-\x25"), "\x7e-\xff");
+ my ($slug) = @_;
+ return uri_escape(encode_utf8($slug), "\x00-\x19\x25-\x25\x7e-\xff");
}
package Atompub::Client::Info;
--
1.6.5.3