Skip to content

Commit

Permalink
better IRI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 8, 2012
1 parent 7c88cb6 commit 596bea2
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 47 deletions.
16 changes: 8 additions & 8 deletions Changes
Expand Up @@ -19,7 +19,7 @@
- Improved tests.
- Fixed bug that prevented Test::Mojo from working with normal Mojolicious
applications that use Mojolicious::Plugin::Config.
- Fixed a few small unicode bugs in documentation.
- Fixed a few small Unicode bugs in documentation.

2.96 2012-05-21
- Added merge method to Mojo::Path.
Expand Down Expand Up @@ -643,7 +643,7 @@
- Changed default keep alive timeout of Mojo::UserAgent from 15 to 20
seconds.
- Improved documentation.
- Improved unicode tests.
- Improved Unicode tests.
- Fixed inline template double encoding bug.

2.36 2011-12-05
Expand Down Expand Up @@ -938,7 +938,7 @@
- Fixed close event bug in Mojo::IOLoop.
- Fixed small redirect_to bug. (judofyr, sri)
- Fixed small attribute selector bug in Mojo::DOM::CSS.
- Fixed small unicode bug in Mojolicious::Plugin::EPRenderer.
- Fixed small Unicode bug in Mojolicious::Plugin::EPRenderer.
- Fixed a few small route bugs.
- Fixed Perl 5.8.7 compatibility.
- Fixed typos.
Expand All @@ -961,7 +961,7 @@
- Fixed small bug that caused exceptions to be logged twice.

1.97 2011-09-03
- Improved unicode handling to be more correct and less forgiving.
- Improved Unicode handling to be more correct and less forgiving.
- Fixed typos.

1.96 2011-09-02
Expand Down Expand Up @@ -1084,7 +1084,7 @@
- Improved Mojo::DOM to allow smart whitespace trimming to be disabled.
(Akron)
- Improved documentation.
- Fixed small unicode bug in get command.
- Fixed small Unicode bug in get command.

1.76 2011-08-12
- Fixed small Mojo::URL escaping bug.
Expand Down Expand Up @@ -1917,8 +1917,8 @@
- Updated WebSocket implementation to draft 76, NOTE THAT THIS CHANGE IS
NOT BACKWARDS COMPATIBLE!!!
(sadly we have no choice when the spec changes)
- Increased Perl version requirement to 5.8.7 due to unicode bugs in
earlier releases.
- Increased Perl version requirement to 5.8.7 due to Unicode bugs in earlier
releases.
- Switched to app->start instead of shagadelic as default way to start
Mojolicious::Lite apps in the documentation.
- Made tutorial examples more business friendly.
Expand Down Expand Up @@ -2193,7 +2193,7 @@
- Updated Mojolicious::Lite tutorial.
- Fixed a case where routes captures got false positives.
- Fixed literal name handling in Mojo::JSON. (rsp)
- Fixed unicode detection in Mojo::JSON. (rsp)
- Fixed Unicode detection in Mojo::JSON. (rsp)
- Fixed multiple small bugs in Mojo::JSON. (rsp)
- Fixed Mojolicious default app tests. (yuki-kimoto)
- Fixed Mojo::Server::FCGI compatibility.
Expand Down
2 changes: 1 addition & 1 deletion README.pod
Expand Up @@ -21,7 +21,7 @@ through L<Mojolicious::Lite>.

Powerful out of the box with RESTful routes, plugins, Perl-ish templates,
session management, signed cookies, testing framework, static file server,
I18N, first class unicode support and much more for you to discover.
I18N, first class Unicode support and much more for you to discover.

=back

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM/CSS.pm
Expand Up @@ -369,7 +369,7 @@ sub _unescape {
# Remove escaped newlines
$value =~ s/\\\n//g;

# Unescape unicode characters
# Unescape Unicode characters
$value =~ s/\\([0-9a-fA-F]{1,6})\s?/pack('U', hex $1)/ge;

# Remove backslash
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/JSON.pm
Expand Up @@ -54,7 +54,7 @@ sub decode {
$self->error('Wide character in input.') and return
unless utf8::downgrade($bytes, 1);

# Detect and decode unicode
# Detect and decode Unicode
my $encoding = 'UTF-8';
$bytes =~ $UTF_PATTERNS->{$_} and $encoding = $_ for keys %$UTF_PATTERNS;
$bytes = Mojo::Util::decode $encoding, $bytes;
Expand Down Expand Up @@ -356,7 +356,7 @@ similar native Perl value.
null -> undef
Decoding UTF-16 (LE/BE) and UTF-32 (LE/BE) will be handled transparently,
encoding will only generate UTF-8. The two unicode whitespace characters
encoding will only generate UTF-8. The two Unicode whitespace characters
C<u2028> and C<u2029> will always be escaped to make JSONP easier.
=head1 ATTRIBUTES
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -531,7 +531,7 @@ Mojo::UserAgent - Non-blocking I/O HTTP 1.1 and WebSocket user agent
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
# Say hello to the unicode snowman with "Do Not Track" header
# Say hello to the Unicode snowman with "Do Not Track" header
say $ua->get('www.☃.net?hello=there' => {DNT => 1})->res->body;
# Quick JSON API request with Basic authentication
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/CodingGuidelines.pod
Expand Up @@ -62,7 +62,7 @@ New features can be marked as experimental to be excluded from deprecation
policies.

A major release is signaled by a new major version number and a unique code
name based on a unicode character.
name based on a Unicode character.

Only add dependencies if absolutely necessary and make them optional if
possible.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -644,8 +644,8 @@ unescaped and decoded to Perl characters.
# GET /☃ (unicode snowman) -> {controller => 'foo', action => 'snowman'}
$r->get('/☃')->to(controller => 'foo', action => 'snowman');

Just don't forget to use the L<utf8> pragma or you'll make the unicode
snowman very sad.
Just don't forget to use the L<utf8> pragma or you'll make the Unicode snowman
very sad.

=head2 WebSockets

Expand Down
2 changes: 1 addition & 1 deletion t/mojo/dom.t
Expand Up @@ -197,7 +197,7 @@ is $dom->at('[foo=bar]')->text, 'works', 'right text';
is $dom->at('[foo=ba]'), undef, 'no result';
is $dom->at('.tset')->text, 'works', 'right text';

# Already decoded unicode snowman and quotes in selector
# Already decoded Unicode snowman and quotes in selector
$dom = Mojo::DOM->new->parse('<div id="snowm&quot;an">☃</div>');
is $dom->at('[id="snowm\"an"]')->text, '', 'right text';
is $dom->at('[id="snowm\22 an"]')->text, '', 'right text';
Expand Down
12 changes: 11 additions & 1 deletion t/mojo/parameters.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 84;
use Test::More tests => 92;

# "Now that's a wave of destruction that's easy on the eyes."
use Mojo::Parameters;
Expand Down Expand Up @@ -167,6 +167,16 @@ $p->parse('input=say%20%22%C2%AB~%22;');
is $p->params->[1], 'say "«~"', 'right value';
is $p->param('input'), 'say "«~"', 'right value';
is "$p", 'input=say+%22%C2%AB~%22', 'right result';
$p = Mojo::Parameters->new('♥=☃');
is $p->params->[0], '', 'right value';
is $p->params->[1], '', 'right value';
is $p->param(''), '', 'right value';
is "$p", '%E2%99%A5=%E2%98%83', 'right result';
$p = Mojo::Parameters->new('%E2%99%A5=%E2%98%83');
is $p->params->[0], '', 'right value';
is $p->params->[1], '', 'right value';
is $p->param(''), '', 'right value';
is "$p", '%E2%99%A5=%E2%98%83', 'right result';

# Reparse
$p = Mojo::Parameters->new('foo=bar&baz=23');
Expand Down
60 changes: 31 additions & 29 deletions t/mojo/url.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 398;
use Test::More tests => 407;

# "I don't want you driving around in a car you built yourself.
# You can sit there complaining, or you can knit me some seat belts."
Expand Down Expand Up @@ -356,6 +356,36 @@ is $url->ihost, 'xn--n3h.net', 'right internationalized host';
is $url->path, '/', 'right path';
is "$url", 'http://xn--n3h.net/', 'right format';

# IRI/IDNA
$url = Mojo::URL->new('http://☃.net/♥/?q=♥☃');
is $url->path->parts->[0], '', 'right path part';
is $url->path, '/%E2%99%A5/', 'right path';
is $url->query, 'q=%E2%99%A5%E2%98%83', 'right query';
is $url->query->param('q'), '♥☃', 'right query value';
$url = Mojo::URL->new('http://☃.net/♥/♥/?♥=☃');
ok $url->is_abs, 'is absolute';
is $url->scheme, 'http', 'right scheme';
is $url->host, '☃.net', 'right host';
is $url->ihost, 'xn--n3h.net', 'right internationalized host';
is $url->path, '/%E2%99%A5/%E2%99%A5/', 'right path';
is $url->path->parts->[0], '', 'right path part';
is $url->path->parts->[1], '', 'right path part';
is $url->query->param(''), '', 'right query value';
is "$url", 'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83',
'right format';
$url = Mojo::URL->new(
'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83');
ok $url->is_abs, 'is absolute';
is $url->scheme, 'http', 'right scheme';
is $url->host, 'xn--n3h.net', 'right host';
is $url->ihost, 'xn--n3h.net', 'right internationalized host';
is $url->path, '/%E2%99%A5/%E2%99%A5/', 'right path';
is $url->path->parts->[0], '', 'right path part';
is $url->path->parts->[1], '', 'right path part';
is $url->query->param(''), '', 'right query value';
is "$url", 'http://xn--n3h.net/%E2%99%A5/%E2%99%A5/?%E2%99%A5=%E2%98%83',
'right format';

# Already absolute
$url = Mojo::URL->new('http://foo.com/');
is $url->to_abs, 'http://foo.com/', 'right absolute version';
Expand All @@ -366,34 +396,6 @@ $url->base->parse('http://sri:foobar@kraih.com:8080/');
my $url2 = $url->to_rel;
is $url->to_rel, 'foo?foo=bar#23', 'right relative version';

# IRI
$url
= Mojo::URL->new('http://sharifulin.ru/привет/?q=шарифулин');
is $url->path->parts->[0], 'привет', 'right path part';
is $url->path, '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/', 'right path';
is $url->query, 'q=%D1%88%D0%B0%D1%80%D0%B8%D1%84%D1%83%D0%BB%D0%B8%D0%BD',
'right query';
is $url->query->param('q'), 'шарифулин', 'right query value';

# IRI/IDNA
$url = Mojo::URL->new(
'http://☃.net/привет/привет/?привет=шарифулин');
ok $url->is_abs, 'is absolute';
is $url->scheme, 'http', 'right scheme';
is $url->host, '☃.net', 'right host';
is $url->ihost, 'xn--n3h.net', 'right internationalized host';
is $url->path, '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82'
. '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/', 'right host';
is $url->path->parts->[0], 'привет', 'right path part';
is $url->path->parts->[1], 'привет', 'right path part';
is $url->query->param('привет'), 'шарифулин',
'right query value';
is "$url",
'http://xn--n3h.net/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82'
. '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/'
. '?%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82='
. '%D1%88%D0%B0%D1%80%D0%B8%D1%84%D1%83%D0%BB%D0%B8%D0%BD', 'right format';

# Empty path elements
$url = Mojo::URL->new('http://kraih.com/foo//bar/23/');
$url->base->parse('http://kraih.com/');
Expand Down

0 comments on commit 596bea2

Please sign in to comment.