Skip to content

Commit

Permalink
Merge pull request #29 from hemberger/fix-deprecations
Browse files Browse the repository at this point in the history
Fix remaining deprecation warnings in PHP 8.1
  • Loading branch information
tburry authored Jan 19, 2022
2 parents 71bceaf + 24cf287 commit 88e23f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 47 deletions.
66 changes: 19 additions & 47 deletions src/BBCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -1437,15 +1437,15 @@ protected function generateOutput($pos) {
$this->lost_start_tags[$name]++;
}

$end = $this->cleanupWSByIteratingPointer($rule['before_endtag'], 0, $output);
$this->cleanupWSByPoppingStack($rule['after_tag'], $output);
$end = $this->cleanupWSByIteratingPointer($rule['before_endtag'] ?? '', 0, $output);
$this->cleanupWSByPoppingStack($rule['after_tag'] ?? '', $output);
$tag_body = $this->collectTextReverse($output, count($output) - 1, $end);

// Note: We don't process 'after_endtag' because the invisible end tag
// always butts up against another tag, so there's *never* any whitespace
// after it. Attempting to process 'after_endtag' would just be a waste
// of time because it'd never match. But 'before_tag' is useful, though.
$this->cleanupWSByPoppingStack($rule['before_tag'], $this->stack);
$this->cleanupWSByPoppingStack($rule['before_tag'] ?? '', $this->stack);

Debugger::debug("<b>Internal_GenerateOutput:</b> optional-tag's content: <tt>"
.htmlspecialchars($tag_body)."</tt><br>\n");
Expand Down Expand Up @@ -1593,15 +1593,11 @@ protected function finishTag($tag_name) {
// do end-tag cleanup by popping, and we do start-tag cleanup by skipping
// $pos forward. (We add one because we've actually rewound the stack
// to the start tag itself.)
if (isset($this->tag_rules[$tag_name]) && isset($this->tag_rules[$tag_name]['after_tag'])) {
$newpos = $this->cleanupWSByIteratingPointer(
$this->tag_rules[$tag_name]['after_tag'],
$pos + 1,
$this->stack
);
} else {
$newpos = $pos + 1;
}
$newpos = $this->cleanupWSByIteratingPointer(
$this->tag_rules[$tag_name]['after_tag'] ?? '',
$pos + 1,
$this->stack
);
$delta = $newpos - ($pos + 1);

if ($this->debug) {
Expand All @@ -1616,11 +1612,7 @@ protected function finishTag($tag_name) {
$output = $this->generateOutput($newpos);

// Clean off any whitespace before the end tag that doesn't belong there.
if (isset($this->tag_rules[$tag_name]) && isset($this->tag_rules[$tag_name]['before_endtag'])) {
$newend = $this->cleanupWSByIteratingPointer($this->tag_rules[$tag_name]['before_endtag'], 0, $output);
} else {
$newend = 0;
}
$newend = $this->cleanupWSByIteratingPointer($this->tag_rules[$tag_name]['before_endtag'] ?? '', 0, $output);
$output = $this->collectTextReverse($output, count($output) - 1, $newend);

if ($this->debug)
Expand Down Expand Up @@ -2146,13 +2138,9 @@ protected function processIsolatedTag($tag_name, $tag_params, $tag_rule) {
return;
}

if (isset($tag_rule['before_tag'])) {
$this->cleanupWSByPoppingStack($tag_rule['before_tag'], $this->stack);
}
$this->cleanupWSByPoppingStack($tag_rule['before_tag'] ?? '', $this->stack);
$output = $this->doTag(self::BBCODE_OUTPUT, $tag_name, $tag_params['_default'], $tag_params, "");
if (isset($tag_rule['after_tag'])) {
$this->cleanupWSByEatingInput($tag_rule['after_tag']);
}
$this->cleanupWSByEatingInput($tag_rule['after_tag'] ?? '');

if ($this->debug) {
Debugger::debug("<b>ProcessIsolatedTag:</b> isolated tag <tt>[".htmlspecialchars($tag_name)
Expand Down Expand Up @@ -2258,17 +2246,9 @@ protected function processVerbatimTag($tag_name, $tag_params, $tag_rule) {
Debugger::debug("<b>Internal_ProcessVerbatimTag:</b> found end tag.<br>\n");

// Clean up whitespace everywhere except before the start tag.
if (isset($tag_rule['after_tag'])) {
$newstart = $this->cleanupWSByIteratingPointer($tag_rule['after_tag'], $start, $this->stack);
} else {
$newstart = $start;
}
if (isset($tag_rule['before_endtag'])) {
$this->cleanupWSByPoppingStack($tag_rule['before_endtag'], $this->stack);
}
if (isset($tag_rule['after_endtag'])) {
$this->cleanupWSByEatingInput($tag_rule['after_endtag']);
}
$newstart = $this->cleanupWSByIteratingPointer($tag_rule['after_tag'] ?? '', $start, $this->stack);
$this->cleanupWSByPoppingStack($tag_rule['before_endtag'] ?? '', $this->stack);
$this->cleanupWSByEatingInput($tag_rule['after_endtag'] ?? '');

// Collect the output from $newstart to the top of the stack, and then
// quickly pop off all of those tokens.
Expand All @@ -2282,9 +2262,7 @@ protected function processVerbatimTag($tag_name, $tag_params, $tag_rule) {

// Clean up whitespace before the start tag (the tag was never pushed
// onto the stack itself, so we don't need to remove it).
if (isset($tag_rule['before_tag'])) {
$this->cleanupWSByPoppingStack($tag_rule['before_tag'], $this->stack);
}
$this->cleanupWSByPoppingStack($tag_rule['before_tag'] ?? '', $this->stack);

// Found the end tag, so process this tag immediately with
// the contents collected between them. Note that we do NOT
Expand Down Expand Up @@ -2508,9 +2486,7 @@ protected function parseEndTagToken() {
$start_tag_params = $start_tag_node[self::BBCODE_STACK_TAG];
$this->computeCurrentClass();

if (isset($this->tag_rules[$tag_name]) && isset($this->tag_rules[$tag_name]['before_tag'])) {
$this->cleanupWSByPoppingStack($this->tag_rules[$tag_name]['before_tag'], $this->stack);
}
$this->cleanupWSByPoppingStack($this->tag_rules[$tag_name]['before_tag'] ?? '', $this->stack);
$start_tag_params['_endtag'] = $tag_params['_tag'];
$start_tag_params['_hasend'] = true;
$output = $this->doTag(
Expand All @@ -2521,9 +2497,7 @@ protected function parseEndTagToken() {
$contents
);

if (isset($this->tag_rules[$tag_name]['after_endtag'])) {
$this->cleanupWSByEatingInput($this->tag_rules[$tag_name]['after_endtag']);
}
$this->cleanupWSByEatingInput($this->tag_rules[$tag_name]['after_endtag'] ?? '');

if ($this->debug) {
Debugger::debug("<b>Internal_ParseEndTagToken:</b> end tag <tt>[/"
Expand Down Expand Up @@ -2610,8 +2584,7 @@ public function parse($string) {
$this->was_limited = false;

// Remove any initial whitespace in pre-trim mode.
if (strlen($this->pre_trim) > 0)
$this->cleanupWSByEatingInput($this->pre_trim);
$this->cleanupWSByEatingInput($this->pre_trim);

// In plain mode, we generate newlines instead of <br> tags.
$newline = $this->plain_mode ? "\n" : "<br>\n";
Expand Down Expand Up @@ -2764,8 +2737,7 @@ public function parse($string) {
Debugger::debug("<hr />\n<b>Parse Done:</b> done main parse; packing stack as text string.<br>\n");

// Remove any trailing whitespace in post-trim mode.
if (strlen($this->post_trim) > 0)
$this->cleanupWSByPoppingStack($this->post_trim, $this->stack);
$this->cleanupWSByPoppingStack($this->post_trim, $this->stack);

// Everything left on the stack should be HTML (or broken tags), so pop it
// all off as plain text, concatenate it, and return it.
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand Down

0 comments on commit 88e23f2

Please sign in to comment.