Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#decodePercent:from:to: and #decodePercentAndPlus:from:to: should also be fixed #1256

Closed
marianopeck opened this issue Jul 8, 2021 · 0 comments

Comments

@marianopeck
Copy link
Contributor

In issue #1157 only #decodePercent: was fixed. However, #decodePercent:from:to: and #decodePercentAndPlus:from:to: should also be fixed as I said here.

My proposed changes:

WAUrl class >> decodePercent: aString from: start to: end
	"percent decodes the string starting at the given index"
	| input output index left |
	index := aString indexOf: $% startingAt: start.
	(index = 0 or: [ index >= end ])
		ifTrue: [ ^ aString copyFrom: start to: end - 1 ].
	input := aString readStream.
	input skip: start - 1. "start index 1 -> skip 0"
	output := WriteStream on: (String new: aString size).
	left := end - start.
	[ left > 0 and: [ input atEnd not ] ] whileTrue: [
		| char |
		char := input next.
		output nextPut: (char = $%
			ifTrue: [
				| firstByte secondByte |
				firstByte :=  self readHexFrom: input errorDetail: aString.
				secondByte :=  self readHexFrom: input errorDetail: aString.
				left := left - 3.
				Character codePoint:firstByte * 16 + secondByte ]
			ifFalse: [
				left := left - 1.
				char ]) ].
	^ output contents

and

WAUrl class >> decodePercentAndPlus: aString from: start to: end
	"percent decodes the given String"
	| percentIndex input output left |
	"check if we contain %"
	percentIndex := aString indexOf: $% startingAt: start.
	(percentIndex = 0 or: [ percentIndex >= end ]) ifTrue: [
		| plusIndex |
		"check if we contain +"
		plusIndex := aString indexOf: $+ startingAt: start.
		(plusIndex = 0 or: [ plusIndex >= end ]) ifTrue: [
			^ aString copyFrom: start to: end - 1 ] ].
	
	"we contain either % or +"
	input := aString readStream.
	input skip: start - 1. "start index 1 -> skip 0"
	output := WriteStream on: (String new: aString size).
	left := end - start.
	[ left > 0 and: [ input atEnd not ] ] whileTrue: [
		| char |
		char := input next.
		output nextPut: (char = $+
			ifTrue: [
				left := left - 1.
				Character space ]
			ifFalse: [
				char = $%
					ifTrue: [
						| firstByte secondByte |
						firstByte :=  self readHexFrom: input errorDetail: aString.
						secondByte :=  self readHexFrom: input errorDetail: aString.
						left := left - 3.
						Character codePoint:firstByte * 16 + secondByte ]
					ifFalse: [
						left := left - 1.
						char ] ]) ].
	^ output contents

ps: sorry I cannot make a PR, but I don't have a Pharo at hand and I don't know how to use Iceberg with Filetree. Hopefully someone can take it from here.

marianopeck added a commit to instantiations/Seaside that referenced this issue Jul 19, 2021
jbrichau pushed a commit that referenced this issue Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants