Jelajahi Sumber

Removed trim() from QRCode->getMatrix(). Data sanitization should be done outside.

Bostjan Rihter 7 tahun lalu
induk
melakukan
788fc0780e
2 mengubah file dengan 9 tambahan dan 1 penghapusan
  1. 2 1
      src/QRCode.php
  2. 7 0
      tests/QRCodeTest.php

+ 2 - 1
src/QRCode.php

@@ -161,7 +161,8 @@ class QRCode{
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	public function getMatrix(string $data):QRMatrix {
-		$data = trim($data);
+    //NOTE: data sanitation should be done outside
+    //$data = trim($data);
 
 		if(empty($data)){
 			throw new QRCodeDataException('QRCode::getMatrix() No data given.');

+ 7 - 0
tests/QRCodeTest.php

@@ -94,6 +94,13 @@ class QRCodeTest extends QRTestAbstract{
 		$this->qrcode->getMatrix('');
 	}
 
+  public function testTrim() {
+    $m1 = $this->qrcode->getMatrix('hello');
+    $m2 = $this->qrcode->getMatrix('hello '); // added space
+
+    $this->assertNotEquals($m1, $m2);
+  }
+
 	public function testImageTransparencyBGDefault(){
 		$this->qrcode = $this->reflection->newInstanceArgs([new QROptions(['imageTransparencyBG' => 'foo'])]);