Skip to content

Commit

Permalink
Merge pull request #7 from g-scalvini/psr-fix
Browse files Browse the repository at this point in the history
Match some PSR-2 and PSR-12 rules
  • Loading branch information
bolknote authored Aug 1, 2023
2 parents ee6fa11 + f354351 commit b01acaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 14 additions & 13 deletions HTML/Safe.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
Expand Down Expand Up @@ -41,7 +42,7 @@
*
* <b>Example:</b>
* <pre>
* $parser = new HTML_Safe;
* $parser = new HTML_Safe();
* $result = $parser->parse($doc);
* </pre>
*
Expand Down Expand Up @@ -320,7 +321,7 @@ protected function writeAttrs($attrs)
}

if ($name == 'style') {
// removes insignificant backslahes
// removes insignificant backslashes
$value = str_replace("\\", '', $value);

// removes CSS comments
Expand Down Expand Up @@ -351,7 +352,7 @@ protected function writeAttrs($attrs)
}
}

$tempval = preg_replace_callback('/&#(\d+);?/m', function ($matches) { return chr($matches[1]); }, $value); //"'
$tempval = preg_replace_callback('/&#(\d+);?/m', function ($matches) { return chr($matches[1]); }, $value);
$tempval = preg_replace_callback(
'/&#x([0-9a-f]+);?/mi',
function ($matches) { return chr(hexdec($matches[1])); },
Expand Down Expand Up @@ -566,7 +567,7 @@ public function escapeHandler(&$parser, $data)
*
* Example:
* <pre>
* $safe = new HTML_Safe;
* $safe = new HTML_Safe();
* $safe->setAllowTags(array('body'));
* </pre>
*
Expand Down Expand Up @@ -644,7 +645,7 @@ public function parse($doc)
$doc = $this->repackUTF7($doc);

// Instantiate the parser
$parser = new XML_HTMLSax3;
$parser = new XML_HTMLSax3();

// Set up the parser
$parser->set_object($this);
Expand All @@ -669,9 +670,9 @@ public function parse($doc)
* @return string Decoded document
* @access private
*/
function repackUTF7($str)
public function repackUTF7($str)
{
return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str);
return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str);
}

/**
Expand All @@ -681,11 +682,11 @@ function repackUTF7($str)
* @return string Recoded string
* @access private
*/
function repackUTF7Callback($str)
public function repackUTF7Callback($str)
{
$str = base64_decode($str[1]);
$str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str);
return preg_replace('/\x00(.)/', '$1', $str);
$str = base64_decode($str[1]);
$str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str);
return preg_replace('/\x00(.)/', '$1', $str);
}

/**
Expand All @@ -695,8 +696,8 @@ function repackUTF7Callback($str)
* @return string Recoded string
* @access private
*/
function repackUTF7Back($str)
public function repackUTF7Back($str)
{
return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-';
return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-';
}
}
5 changes: 3 additions & 2 deletions tests/HTML_SafeTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require_once 'PHPUnit/Framework/TestCase.php';
require_once 'HTML/Safe.php';

Expand All @@ -11,7 +12,7 @@ public function testAllowTags()
$input = '<html><body><p>my text</p></body></html>';
$expected = '<body><p>my text</p></body>';

$safe = new HTML_Safe;
$safe = new HTML_Safe();
$safe->setAllowTags(array('body'));
$this->assertSame($expected, $safe->parse($input));
}
Expand All @@ -24,7 +25,7 @@ public function testSpecialChars()
$inputTwo = '+49-52 <br />';
$expectedTwo = '+49-52 <br />';

$safe = new HTML_Safe;
$safe = new HTML_Safe();
$this->assertSame($expectedOne, $safe->parse($inputOne));
$this->assertSame($expectedTwo, $safe->parse($inputTwo));
}
Expand Down

0 comments on commit b01acaf

Please sign in to comment.