Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.85k stars 527 forks source link

bug+patch on perlfaq9 re:how to create %-encodings on the web #5360

Closed p5pRT closed 20 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#9009 (status was 'resolved')

Searchable as RT9009$

p5pRT commented 22 years ago

From sherwin@saturn.emc.com.ph

Created by win@email.com.ph

It was written in perlfaq9 that

  s/([^\w()'*~!.-])/sprintf '%%%02x'\, $1/eg; # encode

is how you create %-encodings on the web. This doesn't work because sprintf is expecting numeric value. I've included a patch below. :-)

[sherwin@​saturn sherwin]$ perl illustratebug.pl Argument "​:" isn't numeric in sprintf at testbug.pl line 5. Argument "/" isn't numeric in sprintf at testbug.pl line 5. Argument "/" isn't numeric in sprintf at testbug.pl line 5. Argument "/" isn't numeric in sprintf at testbug.pl line 5. Argument "/" isn't numeric in sprintf at testbug.pl line 5. Argument " " isn't numeric in sprintf at testbug.pl line 5. Argument "/" isn't numeric in sprintf at testbug.pl line 5. Argument "#" isn't numeric in sprintf at testbug.pl line 5. http%00%00%00foo.bar%00baz%00foo%00bar%00%0021028461

# --- BEGIN illustratebug.pl

#!/usr/bin/perl -w use strict; (my $s = 'http​://foo.bar/baz/foo bar/#21028461')   =~ s/([^\w()'*~!\.-])/sprintf '%%%02x'\, $1/eg; print "$s\n"; exit 0;

# --- END illustratebug.pl

# --- BEGIN perlfaq9.pod.patch

*** perl-5.6.1/pod/perlfaq9.pod.orig Sun Apr 8 14​:09​:16 2001 --- perl-5.6.1/pod/perlfaq9.pod Wed Apr 24 20​:29​:57 2002 *************** *** 219\,227 ****   The best source of detailed information on URI encoding is RFC 2396.   Basically\, the following substitutions do it​:

! s/([^\w()'*~!.-])/sprintf '%%%02x'\, $1/eg; # encode

! s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode

  However\, you should only apply them to individual URI components\, not   the entire URI\, otherwise you'll lose information and generally mess --- 219\,227 ----   The best source of detailed information on URI encoding is RFC 2396.   Basically\, the following substitutions do it​:

! s/([^\w()'*~!.-])/sprintf '%%%02x'\, ord $1/eg; # encode

! s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode

  However\, you should only apply them to individual URI components\, not   the entire URI\, otherwise you'll lose information and generally mess

# --- END perlfaq9.pod.patch

Perl Info ``` Flags: category=docs severity=low Site configuration information for perl v5.6.1: Configured by compil at Thu Feb 21 00:59:47 EST 2002. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=linux, osvers=2.4.16-6mdksmp, archname=i386-linux uname='linux bi.mandrakesoft.com 2.4.16-6mdksmp #1 smp sat dec 8 04:02:48 cet 2001 i686 unknown ' config_args='-des -Darchname=i386-linux -Dd_dosuid -Ud_csh -Duseshrplib -Doptimize=-O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math -fno-strength-reduce -Dprefix=/usr -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Uuselargefiles -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/lib/perl5/man/man3' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -I/usr/local/include', optimize='-O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math -fno-strength-reduce', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 20000731 (Mandrake Linux 8.2 2.96-0.75mdk)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -ldl -lm -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.2.4.so, so=so, useshrplib=true, libperl=libperl.so Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.6.1/i386-linux/CORE' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.6.1: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl . Environment for perl v5.6.1: HOME=/home/sherwin LANG=en_US LANGUAGE=en_US:en LC_COLLATE=en_US LC_CTYPE=en_US LC_MESSAGES=en_US LC_MONETARY=en_US LC_NUMERIC=en_US LC_TIME=en_US LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/games:/home/sherwin/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 22 years ago

From @jhi

On Wed\, Apr 24\, 2002 at 09​:45​:45PM +0800\, Sherwin Daganato wrote​:

This is a bug report for perl from win@​email.com.ph\, generated with the help of perlbug 1.33 running under perl v5.6.1.

It seems that this bug has been already corrected in the latest version of the FAQ (http​://faq.perl.org/perlfaq9\, the HTML formatting seems to be a bit off\, but the ord() is there.)

-- $jhi++; # http​://www.iki.fi/jhi/   # There is this special biologist word we use for 'stable'.   # It is 'dead'. -- Jack Cohen