Skip to content
Snippets Groups Projects
Verified Commit 078b253f authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

:bug: Fix our own implementation of “contains” with special characters in the pattern

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 e9d79796), because
Windows paths typically contain antislashes.
parent e69c8507
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment