'From Squeak3.7alpha of ''11 September 2003'' [latest update: #5607] on 24 December 2003 at 4:22:38 pm'! "Change Set: UrlPortNumberExtractFix-mu Date: 24 December 2003 Author: Masashi Umezawa HierarchicalUrl>>privateInitializeFromText: extracts a port number in URL, but it does not perform any error checking. It silently generates invalid URL instances. Now the method checks invalid port number in parsing. -Should pass: Url absoluteFromText: 'http://swikis.ddo.jp:8823/' -Should raise errors: (after the patch) Url absoluteFromText: 'http://swikis.ddo.jp:-1/' Url absoluteFromText: 'http://swikis.ddo.jp:65536/' Url absoluteFromText: 'http://swikis.ddo.jp:auau/' "! !HierarchicalUrl methodsFor: 'parsing' stamp: 'mu 12/24/2003 16:03'! privateInitializeFromText: aString | remainder ind specifiedSchemeName | remainder := aString. schemeName ifNil: [specifiedSchemeName := Url schemeNameForString: remainder. specifiedSchemeName ifNotNil: [schemeName := specifiedSchemeName. remainder := remainder copyFrom: schemeName size + 2 to: remainder size]. schemeName ifNil: ["assume HTTP" schemeName := 'http']]. "remove leading // if it's there" (remainder beginsWith: '//') ifTrue: [remainder := remainder copyFrom: 3 to: remainder size]. "get the query" ind := remainder indexOf: $?. ind > 0 ifTrue: [query := remainder copyFrom: ind + 1 to: remainder size. remainder := remainder copyFrom: 1 to: ind - 1]. "get the authority" ind := remainder indexOf: $/. ind > 0 ifTrue: [ind = 1 ifTrue: [authority := ''] ifFalse: [authority := remainder copyFrom: 1 to: ind - 1. remainder := remainder copyFrom: ind + 1 to: remainder size]] ifFalse: [authority := remainder. remainder := '']. "Extract the port" (authority includes: $:) ifTrue: [| lastColonIndex portString | lastColonIndex := authority findLast: [:c | c = $:]. portString := authority copyFrom: lastColonIndex + 1 to: authority size. portString isAllDigits ifTrue: [port := Integer readFromString: portString. (port > 65535) ifTrue: [self error: 'Invalid port number']. authority := authority copyFrom: 1 to: lastColonIndex - 1] ifFalse:[self error: 'Invalid port number']]. "extract the username+password" (authority includes: $@) ifTrue: [username := authority copyUpTo: $@. authority := authority copyFrom: (authority indexOf: $@) + 1 to: authority size. (username includes: $:) ifTrue: [password := username copyFrom: (username indexOf: $:) + 1 to: username size. username := username copyUpTo: $:]]. "get the path" path := self privateParsePath: remainder relativeTo: #() .! !