[Seaside] Encoding problem
Johan Brichau
johan at inceptive.be
Wed May 21 05:25:23 UTC 2014
Thanks Sven!
3.1.1 is about to be released, so let's see if we can sneak this fix in.
Johan
On 20 May 2014, at 23:45, Sven Van Caekenberghe <sven at stfx.eu> wrote:
>
> On 20 May 2014, at 23:15, Sven Van Caekenberghe <sven at stfx.eu> wrote:
>
>> The error is in
>>
>> GRPharoUtf8CodecStream>>#greaseNext:putAllFast:startingAt:
>>
>> the first escape clause in the whileFalse computes a wrong first argument to #greaseNext:putAllFast:startingAt:
>>
>> however, it is a bit hard to say what the correct one should be, I will try with
>>
>> startIndex + anInteger - lastIndex
>>
>> I hope there are enough tests.
>
> I added an extra assert
>
> self assert: 'ab', umlaut next: 1 startingAt: 1 gives: 'a'.
>
> to GRPharoCodecTest>>#testGreaseNextPutAllStartingAt so that it now reads:
>
> | umlaut encodedUmlaut |
> umlaut := String with: (Character value: 228).
> encodedUmlaut := String with: (Character value: 195) with: (Character value: 164).
> self assert: 'ab' next: 1 startingAt: 1 gives: 'a'.
> self assert: 'a', umlaut, 'b' next: 1 startingAt: 1 gives: 'a'.
> self assert: 'ab', umlaut next: 1 startingAt: 1 gives: 'a'.
> self assert: 'a', umlaut, 'b' next: 2 startingAt: 1 gives: 'a', encodedUmlaut.
> self assert: 'a', umlaut, 'b' next: 1 startingAt: 2 gives: encodedUmlaut.
> self assert: 'a', umlaut, 'b' next: 2 startingAt: 2 gives: encodedUmlaut, 'b'.
> self assert: 'a', umlaut, umlaut next: 2 startingAt: 2 gives: encodedUmlaut, encodedUmlaut.
> self assert: 'ab', umlaut, 'b', umlaut next: 3 startingAt: 2 gives: 'b', encodedUmlaut, 'b'
>
> it fails before the proposed change, it succeeds after it - and the functional test now passes.
>
> Final code of GRPharoUtf8CodecStream>>#greaseNext:putAllFast:startingAt:
>
> | lastIndex nextIndex |
> lastIndex := startIndex.
> nextIndex := ByteString findFirstInString: aByteString inSet: Latin1ToUtf8Map startingAt: lastIndex.
> nextIndex = 0 ifTrue: [ ^ stream greaseNext: anInteger putAll: aByteString startingAt: startIndex ].
> [
> nextIndex >= (startIndex + anInteger) ifTrue: [
> ^ stream greaseNext: startIndex + anInteger - lastIndex putAll: aByteString startingAt: lastIndex ].
> nextIndex > lastIndex ifTrue: [
> stream greaseNext: nextIndex - lastIndex putAll: aByteString startingAt: lastIndex ].
> stream nextPutAll: (Latin1ToUtf8Encodings at: (aByteString byteAt: nextIndex) + 1).
> lastIndex := nextIndex + 1.
> nextIndex := ByteString findFirstInString: aByteString inSet: Latin1ToUtf8Map startingAt: lastIndex.
> (nextIndex = 0 or: [ nextIndex >= (startIndex + anInteger) ]) ] whileFalse.
> lastIndex >= (startIndex + anInteger) ifFalse: [
> stream greaseNext: startIndex + anInteger - lastIndex putAll: aByteString startingAt: lastIndex ]
>
> But this certainly needs another pair of eyes.
>
> Sven
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
More information about the seaside
mailing list