[svn:parrot] r46846 - in trunk: runtime/parrot/library t/library
fperrad at svn.parrot.org
fperrad at svn.parrot.org
Fri May 21 07:59:17 UTC 2010
Author: fperrad
Date: Fri May 21 07:59:17 2010
New Revision: 46846
URL: https://trac.parrot.org/parrot/changeset/46846
Log:
[URI] add userinfo()
Modified:
trunk/runtime/parrot/library/URI.pir
trunk/t/library/uri.t
Modified: trunk/runtime/parrot/library/URI.pir
==============================================================================
--- trunk/runtime/parrot/library/URI.pir Fri May 21 07:13:31 2010 (r46845)
+++ trunk/runtime/parrot/library/URI.pir Fri May 21 07:59:17 2010 (r46846)
@@ -280,16 +280,40 @@
$P0 = subclass ['URI';'_generic'], ['URI';'_server']
.end
-=item host
+=item userinfo
=cut
-.sub 'host' :method
+.sub 'userinfo' :method
$S0 = self.'authority'()
- $I0 = index $S0, ':'
+ $I0 = index $S0, '@'
if $I0 < 0 goto L1
$S0 = substr $S0, 0, $I0
+ .return ($S0)
+ L1:
+ .return ('')
+.end
+
+=item host
+
+=cut
+
+.sub 'host' :method
+ $S0 = self.'authority'()
+ .local int pos, lastpos
+ lastpos = length $S0
+ pos = 0
L1:
+ pos = index $S0, ':', pos
+ if pos < 0 goto L2
+ $I1 = pos
+ inc pos
+ $I0 = is_cclass .CCLASS_NUMERIC, $S0, pos
+ unless $I0 goto L1
+ $I0 = find_not_cclass .CCLASS_NUMERIC, $S0, pos, lastpos
+ unless $I0 == lastpos goto L1
+ $S0 = substr $S0, 0, $I1
+ L2:
.return ($S0)
.end
@@ -301,8 +325,10 @@
$S0 = self.'authority'()
.local int pos, lastpos
lastpos = length $S0
- pos = index $S0, ':'
- if pos < 0 goto L1
+ pos = 0
+ L1:
+ pos = index $S0, ':', pos
+ if pos < 0 goto L2
inc pos
$I0 = is_cclass .CCLASS_NUMERIC, $S0, pos
unless $I0 goto L1
@@ -310,7 +336,7 @@
unless $I0 == lastpos goto L1
$S1 = substr $S0, pos
.return ($S1)
- L1:
+ L2:
.tailcall self.'default_port'()
.end
Modified: trunk/t/library/uri.t
==============================================================================
--- trunk/t/library/uri.t Fri May 21 07:13:31 2010 (r46845)
+++ trunk/t/library/uri.t Fri May 21 07:59:17 2010 (r46846)
@@ -21,7 +21,7 @@
load_bytecode 'URI.pir'
- plan(53)
+ plan(60)
test_new()
test_uri()
test_file()
@@ -158,6 +158,21 @@
is($S0, '127.0.0.1', 'host')
$S0 = $P0.'port'()
is($S0, '8080', 'port')
+
+ $P0 = factory('http://user:passwd@proxy.net:8000/path')
+ ok($P0, "http://user:passwd@proxy.net:8000/path")
+ $I0 = isa $P0, ['URI';'http']
+ ok($I0, "isa ['URI';'http']")
+ $S0 = $P0.'scheme'()
+ is($S0, 'http', "scheme")
+ $S0 = $P0.'authority'()
+ is($S0, 'user:passwd at proxy.net:8000', 'authority')
+ $S0 = $P0.'userinfo'()
+ is($S0, 'user:passwd', 'userinfo')
+ $S0 = $P0.'host'()
+ is($S0, 'user:passwd at proxy.net', 'host')
+ $S0 = $P0.'port'()
+ is($S0, '8000', 'port')
.end
.sub 'test_https'
More information about the parrot-commits
mailing list