Просмотр исходного кода

Merge pull request #15 from wickedsheep/fix_input_trim

Fix input trim
smiley 7 лет назад
Родитель
Сommit
b8d8de8db1
2 измененных файлов с 10 добавлено и 2 удалено
  1. 3 2
      src/QRCode.php
  2. 7 0
      tests/QRCodeTest.php

+ 3 - 2
src/QRCode.php

@@ -161,8 +161,9 @@ class QRCode{
 	 * @throws \chillerlan\QRCode\Data\QRCodeDataException
 	 */
 	public function getMatrix(string $data):QRMatrix {
-		$data = trim($data);
-
+		//NOTE: input sanitization 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'])]);