[BUG][FIX] Accept lowercase hex in URL escapes

Duane Maxwell dmaxwell at exobox.com
Fri Jun 2 01:34:46 UTC 2000


'From Squeak2.8alpha of 26 April 2000 [latest update: #2210] on 1 June 2000
at 6:33:03 pm'!
"Change Set:		StringUnescape
Date:			1 June 2000
Author:			Duane Maxwell

Lower case hex digits in percent escapes are legal in URLs.  This changeset
coerces escapes to uppercase before sending them off to
Integer>>readFrom:base"!

!String methodsFor: 'internet' stamp: 'DSM 6/1/2000 18:15'!
unescapePercents
 "change each %XY substring to the character with ASCII value XY in hex.
This is the opposite of #encodeForHTTP"
	| inStream ans c tok asciiVal |
	inStream _ ReadStream on: self.
	ans _ WriteStream on: String new.
	[ c _ inStream next.  c = nil ] whileFalse: [
		c = $+ ifTrue: [ ans nextPut: $ ] ifFalse: [
			(c = $%) ifTrue: [
				tok _ (inStream next: 2) asUppercase.
				asciiVal _ Integer readFrom:
					(ReadStream on: tok) base: 16.
				ans nextPut: (Character value: asciiVal). ]
			ifFalse: [
				ans nextPut: c ] ] ].

	^ans contents ! !





More information about the Squeak-dev mailing list