Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#2564 Submission title and sub title with HTML tag handling #25

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions filter/ArticleCrossrefXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public function createJournalArticleNode($doc, $submission)

// title
$titlesNode = $doc->createElementNS($deployment->getNamespace(), 'titles');
$titlesNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'title', htmlspecialchars($publication->getLocalizedTitle($locale), ENT_COMPAT, 'UTF-8')));
if ($subtitle = $publication->getData('subtitle', $locale)) {
$titlesNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'title', htmlspecialchars($publication->getLocalizedTitle($locale, 'html'), ENT_COMPAT, 'UTF-8')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will lead these fields to be double-escaped. A title containing markup should look like:

<title>E=mc<sup>2</sup></title>

...but the call to htmlspecialchars will cause it to look like...

<title>E=mc&lt;sup&gt;2&lt;/sup&gt;</title>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmecher htmlspecialchars was there before my changes . Was that a mistake ? Also considering the following title

<title>Albert Einstein great formula "E=MC<sup>2</sup>" allow us to measure the released energy by nuclear fusion</title>

Do we allow quotes(single or double) in title ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

htmlspecialchars made sense with plaintext content (it will make sure that < > & will be interpreted as text characters, not HTML entities) but now that we're allowing HTML it'll need to be changed for the appropriate filtering function. We do allow quotes in titles.

if ($subtitle = $publication->getLocalizedSubTitle($locale, 'html')) {
$titlesNode->appendChild($node = $doc->createElementNS($deployment->getNamespace(), 'subtitle', htmlspecialchars($subtitle, ENT_COMPAT, 'UTF-8')));
}
$journalArticleNode->appendChild($titlesNode);
Expand Down