From d7d279f61896dcceba54407452e3e6aae768597c Mon Sep 17 00:00:00 2001 From: Ere Maijala <ere.maijala@helsinki.fi> Date: Thu, 11 Jun 2015 09:17:34 +0300 Subject: [PATCH] Sanitize PIN code so that it works the way it does in Voyager. --- module/VuFind/src/VuFind/ILS/Driver/Voyager.php | 16 +++++++++++++++- .../src/VuFind/ILS/Driver/VoyagerRestful.php | 8 ++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php index a0f671e04f1..2469be81108 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/Voyager.php +++ b/module/VuFind/src/VuFind/ILS/Driver/Voyager.php @@ -1156,6 +1156,19 @@ class Voyager extends AbstractBase ? [] : $this->getPurchaseHistoryData($id); } + /** + * Sanitize patron PIN code (remove characters Voyager doesn't handle properly) + * + * @param string $pin PIN code to sanitize + * + * @return string Sanitized PIN code + */ + protected function sanitizePIN($pin) + { + $pin = preg_replace('/[^0-9a-zA-Z#&<>+^`~]+/', '', $pin); + return $pin; + } + /** * Patron Login * @@ -1216,7 +1229,8 @@ class Voyager extends AbstractBase ? mb_strtolower(utf8_encode($row['FALLBACK_LOGIN']), 'UTF-8') : null; - if ((!is_null($primary) && $primary == $compareLogin) + if ((!is_null($primary) && ($primary == $compareLogin + || $primary == $this->sanitizePIN($compareLogin))) || ($fallback_login_field && is_null($primary) && $fallback == $compareLogin) ) { diff --git a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php index aa58c03b72a..84806a944ec 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php +++ b/module/VuFind/src/VuFind/ILS/Driver/VoyagerRestful.php @@ -3150,14 +3150,18 @@ EOT; $lastname = htmlspecialchars($patron['lastname'], ENT_COMPAT, 'UTF-8'); $ubId = htmlspecialchars($this->ws_patronHomeUbId, ENT_COMPAT, 'UTF-8'); $oldPIN = trim( - htmlspecialchars($details['oldPassword'], ENT_COMPAT, 'UTF-8') + htmlspecialchars( + $this->sanitizePIN($details['oldPassword']), ENT_COMPAT, 'UTF-8' + ) ); if ($oldPIN === '') { // Voyager requires the PIN code to be set even if it was empty $oldPIN = ' '; } $newPIN = trim( - htmlspecialchars($details['newPassword'], ENT_COMPAT, 'UTF-8') + htmlspecialchars( + $this->sanitizePIN($details['newPassword']), ENT_COMPAT, 'UTF-8' + ) ); $barcode = htmlspecialchars($patron['cat_username'], ENT_COMPAT, 'UTF-8'); -- GitLab