Skip to content

Commit

Permalink
Revert "Merge remote-tracking branch 'origin/bugs-5879' into bugs-5880"
Browse files Browse the repository at this point in the history
This reverts commit 77f0832.
  • Loading branch information
jazzsequence committed May 15, 2023
1 parent 3534a9c commit 57f440a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
22 changes: 2 additions & 20 deletions php/pantheon/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use \Symfony\Component\Filesystem\Filesystem;
use \Symfony\Component\Finder\Finder;
use \Pantheon\Utils as Pantheon;

class Utils {
static $fs;
Expand Down Expand Up @@ -59,27 +60,8 @@ public static function sanitize_data($data, $sanitizer_function = 'htmlspecialch
array_map('self::sanitize_data', array_values((array)$data))
);
return is_object( $data ) ? (object)$sanitized_data : $sanitized_data;
} elseif ( is_integer( $data ) ) {
} elseif ( is_integer($data) ) {
return (string)$data;
} elseif ( is_string( $data ) ) {
if ( ! empty( $data ) ) {
$dom = new \DOMDocument;
$dom->loadHTML( $data );
$anchors = $dom->getElementsByTagName('a');

// Bail if our string does not only contain an anchor tag.
if ( 0 === $anchors->length ) {;
return $sanitizer_function($data);
}

$href = $anchors[0]->getAttribute('href');
$sanitized_href = call_user_func($sanitizer_function, $href);
$sanitized_link_text = call_user_func($sanitizer_function, $anchors[0]->textContent);

// Rebuild anchor tags to ensure there are no injected attributes.
$rebuilt_link = '<a href="' . $sanitized_href . ' target="_blank"">' . $sanitized_link_text . '</a>';
return $rebuilt_link;
}
}

return $sanitizer_function($data);
Expand Down
8 changes: 2 additions & 6 deletions php/pantheon/views/table.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

use Pantheon\Utils; ?>

<table class='table table-condensed'>
<thead>
<tr>
<?php if(isset($headers)): ?>
<?php foreach ($headers as $header): ?>
<th><?php echo Utils::sanitize_data( $header ); ?></th>
<th><?php echo $header; ?></th>
<?php endforeach; ?>
<?php endif; ?>
</tr>
Expand All @@ -16,7 +12,7 @@
<?php foreach($rows as $row): ?>
<tr class="<?php if(isset($row['class'])) { echo $row['class']; } ?>">
<?php foreach($row['data'] as $values): ?>
<td><?php echo Utils::sanitize_data( $values ); ?></td>
<td><?php echo $values; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
Expand Down

0 comments on commit 57f440a

Please sign in to comment.