From 078b253f6121b55f77f2648e7488a1da521b23d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 5 Dec 2024 16:36:31 +0100
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20our=20own=20implementation?=
 =?UTF-8?q?=20of=20=E2=80=9Ccontains=E2=80=9D=20with=20special=20character?=
 =?UTF-8?q?s=20in=20the=20pattern?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Previously, “contains('foo\', '\')” would fail with an error, due to the
antislash not being escaped when calling the “regexp” function. Same for other
special characters in regular expressions (e.g. the dollar sign).

In particular, this bug would make Dynare unusable with Octave under
Windows (since commit e9d79796cf7ddfe483f60bc1f5773ade6cc72e34), because
Windows paths typically contain antislashes.
---
 matlab/missing/contains/contains.m | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/matlab/missing/contains/contains.m b/matlab/missing/contains/contains.m
index 858fddb20f..d14cd5daa6 100644
--- a/matlab/missing/contains/contains.m
+++ b/matlab/missing/contains/contains.m
@@ -12,7 +12,7 @@ function tf = contains(string, pattern, varargin)
 % OUTPUT
 % - tf   [logical]
 %
-% Copyright © 2019 Dynare Team
+% Copyright © 2019-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -62,9 +62,9 @@ end
 
 tf = false(size(string));
 for ii = 1:numel(pattern)
-    idx = regexp(string, pattern{ii});
+    idx = regexp(string, regexptranslate('escape', pattern{ii}));
     for jj = 1:numel(string)
         tf(jj) = tf(jj) || ~isempty(idx{jj});
     end
 end
-end
\ No newline at end of file
+end
-- 
GitLab