<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><font face="Georgia">The culprit is</font></p>
    <p><font face="Georgia">'From Squeak6.0alpha of 9 September 2017
        [latest update: #17382] on 21 January 2018 at 6:58:58 am'!<br>
        <br>
        !MultiByteFileStream methodsFor: 'accessing' stamp: 'raa
        1/21/2018 06:57'!<br>
        upToPosition: anInteger<br>
            "Answer a subcollection containing items starting from the
        current position and ending including the given position.
        Usefully different to #next: in that positions measure *bytes*
        from the file, where #next: wants to measure *characters*."<br>
            ^self collectionSpecies new: 1000 streamContents: [ :stream
        |<br>
                | ch |<br>
                [ (ch := self next) == nil or: [ self position >
        anInteger ] ] <br>
                    whileFalse: [ stream nextPut: ch ] ]! !<br>
      </font></p>
    <p><font face="Georgia">which was referencing the instVar
        <position> directly. Changing that to "self position"
        allows it to stop at the right place.</font><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 1/20/18 4:24 PM, Bernhard Pieber
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:645F0CC4-4ADA-4328-92D1-C5E29B326056@pieber.com">
      <pre wrap="">Hi everyone,

I think I found a really strange bug in MultiByteFileStream. I am on macOS Sierra and used the latest VM from bintray and an updated trunk image.

I try to parse anchors from a UTF-8 encoded HTML file (see attachment). It uses a MultiByteFileStream with a UTF8TextConverter.

Here is the code that shows the bug:

FileStream readOnlyFileNamed: 'test.html' do: [:stream | 
        | result |
        result := OrderedCollection new.
        [stream atEnd] whileFalse: [
                stream match: '<A HREF="'.
                result add: (stream upToAll: '</A>')].
        result at: 13
].

It answers the following string:
'<a class="moz-txt-link-freetext" href="https://www.europa.de/produkte/lebensversicherung">https://www.europa.de/produkte/lebensversicherung</a>">Darlehen sichern: Variable Risiko-Lebensversicherung</A>
                                <DT><A HREF=<a class="moz-txt-link-rfc2396E" href="http://orf.at/stories/2358210/2358209/">"http://orf.at/stories/2358210/2358209/"</a>>Banken im Zinsdilemma</A>
                        </DL><p>
                </DL><p>
        </DL><p>
</HTML>
'

You can see that it did not stop at the </A> as it should have but answers the rest of the file. The strange thing is that the next anchor looks like this:
'<a class="moz-txt-link-freetext" href="http://orf.at/stories/2358210/2358209/">http://orf.at/stories/2358210/2358209/</a>">Banken im Zinsdilemma</A>
                        </DL><p>
                </DL><p>
        </DL><p>
</HTML>
'
So it read part of the file again.

I tried making the file smaller but the bug goes away then.

As a cross check when I read the whole file at once it parses correctly.

FileStream readOnlyFileNamed: 'test.html' do: [:fileStream | 
        | stream result |
        stream := fileStream contentsOfEntireFile readStream.
        result := OrderedCollection new.
        [stream atEnd] whileFalse: [
                stream match: '<A HREF="'.
                result add: (stream upToAll: '</A>')].
        result at: 13
].

Any ideas anyone?

Bernhard

</pre>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>