From f6c0c692d98598c44877e2d4106396c603315222 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Wed, 17 Oct 2018 11:04:12 +0200
Subject: [PATCH] :ambulance: fix(attributes) Improve use of pattern attribute

issue #5910
---
 include/simpleplugin/attributes/class_StringAttribute.inc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/simpleplugin/attributes/class_StringAttribute.inc b/include/simpleplugin/attributes/class_StringAttribute.inc
index f76587bae..3ea86764b 100644
--- a/include/simpleplugin/attributes/class_StringAttribute.inc
+++ b/include/simpleplugin/attributes/class_StringAttribute.inc
@@ -56,8 +56,10 @@ class StringAttribute extends Attribute
   function setPattern ($pattern)
   {
     $this->pattern = $pattern;
-    if (preg_match('/^(.)(.*)\1$/', $pattern, $m)) {
-      // First and last characters are the same means no modifiers are in use
+    if (preg_match('/^(.)\^(.*)\$\1$/', $pattern, $m)) {
+      /* Only convert anchored patterns
+       * First and last characters are the same means no modifiers are in use
+       */
       $this->html5pattern = $m[2];
     } else {
       $this->html5pattern = NULL;
@@ -78,7 +80,7 @@ class StringAttribute extends Attribute
       $attributes['autocomplete'] = ($this->autocomplete ? 'on' : 'off' );
     }
     if ($this->html5pattern !== NULL) {
-      $attributes['pattern'] = htmlentities($this->html5pattern, ENT_COMPAT, 'UTF-8');
+      $attributes['pattern'] = '{literal}'.htmlentities($this->html5pattern, ENT_COMPAT, 'UTF-8').'{/literal}';
     }
     if ($this->isRequired()) {
       $attributes['required'] = 'required';
-- 
GitLab