Skip to content

Commit

Permalink
make sure __toString always delivers same result for base64 and quote…
Browse files Browse the repository at this point in the history
…d printable encoding, prevents wrong dkim signatures
  • Loading branch information
frederikbosch committed Dec 6, 2017
1 parent 04ea000 commit 5840b0d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Stream/Base64EncodedStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private function removeFilter(): void
*/
public function __toString(): string
{
$this->rewind();
return $this->decoratedStream->__toString();
}

Expand Down
1 change: 1 addition & 0 deletions src/Stream/QuotedPrintableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private function removeFilter(): void
*/
public function __toString(): string
{
$this->rewind();
return $this->decoratedStream->__toString();
}

Expand Down
15 changes: 15 additions & 0 deletions test/Stub/BugReport/issue-30.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Deze e-mail online lezen

*Nieuwsbrief december 2017*

Goedendag,

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur iaculis velit ac blandit
rutrum. Donec imperdiet hendrerit placerat. Donec suscipit ut leo vel laoreet. Curabitur
facilisis nunc ac urna laoreet finibus vitae luctus odio. Ut porttitor tempor hendrerit.
Interdum et malesuada fames ac ante ipsum primis in faucibus. Fusce sollicitudin placerat
scelerisque. Quisque luctus sapien quis augue malesuada, ac fringilla augue luctus. Vestibulum
pharetra et libero at pellentesque. Sed non semper magna. Fusce auctor sit amet ex vitae euismod.
Sed nec arcu a est molestie ullamcorper.

*12 januari congres Impact van ullamcorper op auctor et ABC*
11 changes: 11 additions & 0 deletions test/Unit/Stream/Base64StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,15 @@ function ($line) {
$this->assertLessThanOrEqual(76, max($lines));
}

/**
* @test
*/
public function it_produces_equally_result_with_to_string_twice()
{
$stream = Base64EncodedStream::fromString(
file_get_contents(__DIR__.'/../../Stub/BugReport/issue-30.txt')
);

$this->assertEquals((string)$stream, (string)$stream);
}
}
12 changes: 12 additions & 0 deletions test/Unit/Stream/QuotedPrintableStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,16 @@ public function it_uses_correct_line_endings_tab()
$this->assertEquals(str_repeat("tëst1\ttest2\r\n", 50), quoted_printable_decode($encoded));
}

/**
* @test
*/
public function it_produces_equally_result_with_to_string_twice()
{
$stream = QuotedPrintableStream::fromString(
file_get_contents(__DIR__.'/../../Stub/BugReport/issue-30.txt')
);

$this->assertEquals((string)$stream, (string)$stream);
}

}

0 comments on commit 5840b0d

Please sign in to comment.