Skip to content

Commit

Permalink
CleanHTML: Add some list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 26, 2024
1 parent cccf75c commit ef6f895
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/cleanhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function clean($t) {
}
if ($p === $endp) {
if ($endp === $len) {
$this->lerror("<0>Unclosed HTML tag", $tagp, $p);
$this->lerror("<0>Unclosed tag", $tagp, $p);
}
$x .= ">";
$xp = $endp - 1;
Expand Down Expand Up @@ -509,7 +509,7 @@ function clean($t) {
$x .= substr($t, $xp);
}
if ($this->opentags) {
$this->lerror("<0>Unclosed HTML tag", $this->opentags->pos1, $this->opentags->pos2);
$this->lerror("<0>Unclosed tag", $this->opentags->pos1, $this->opentags->pos2);
}

$this->context = $this->opentags = null;
Expand Down Expand Up @@ -539,6 +539,11 @@ function message_list() {
return $this->ml;
}

/** @return string */
function full_feedback_text() {
return MessageSet::feedback_text($this->ml);
}

/** @return CleanHTML */
static function basic() {
if (!self::$main) {
Expand Down
13 changes: 13 additions & 0 deletions test/t_cleanhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ function test_void() {
xassert_eqq($chtml->clean('<br / >'), '<br>');
xassert_eqq($chtml->clean('<div / >'), false);
}

function test_li() {
$chtml = CleanHTML::basic();
xassert_eqq($chtml->clean('<ul> <li> A </li> <li> B </li> </ul>'), '<ul> <li> A </li> <li> B </li> </ul>');
$t = "<h2>ACM CCS 2025 - Cycle A</h2>\n<ul>\n<li><a href=\"https://www.sigsac.org/ccs/CCS2024/call-for/call-for-papers.html\">Call for Papers</a></li>\n<li><a href=\"https://www.acm.org/publications/policies/new-acm-policy-on-authorship\">ACM Authorship policies</a></li>\n</ul>";
xassert_eqq($chtml->clean($t), $t);
}

function test_table() {
$chtml = CleanHTML::basic();
$t = "Conflict of interest guidelines:\n<table border=\"1\">\n <tbody>\n <tr>\n <td>\n <div>1. Between advisors and advisees: permanent.</div>\n </td>\n </tr>\n <tr>\n <td>\n <div>2. Between family members (if they could be potential reviewers): permanent.</div>\n </td>\n </tr>\n <tr>\n <td>\n <div>\n 3. Between individuals who have collaborated in the past <b>5 years</b>. Collaboration includes joint research, projects, papers, or direct funding (not corporate funding) from the potential reviewer to an author. Co-participation in professional activities, such as tutorials, is not considered a conflict.\n </div>\n </td>\n </tr>\n <tr>\n <td>\n <div>4. Between individuals from the same institution, or who were at the same institution within the last <b>5 years</b>.</div>\n </td>\n </tr>\n <tr>\n <td>\n <div>5. Between individuals whose relationship could compromise objectivity in the review process.</div>\n </td>\n </tr>\n </tbody>\n</table>";
xassert_eqq($chtml->clean($t), $t);
}
}

0 comments on commit ef6f895

Please sign in to comment.