Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b954720

Browse files
author
livecodeali
committed
Merge remote-tracking branch 'upstream/develop-7.0' into merge-develop-7.0_15.12.15
2 parents f7bef80 + 1878499 commit b954720

File tree

5 files changed

+229
-3
lines changed

5 files changed

+229
-3
lines changed

docs/notes/bugfix-16577.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SpecialFolderPath("resources") doesn't work in substack

docs/notes/bugfix-16584.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Filtering with wildcards broken in very specific edge case

engine/src/sysspec.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ void MCS_getresourcesfolder(bool p_standalone, MCStringRef &r_resources_folder)
378378
uindex_t t_slash_index;
379379
MCStringRef t_stack_filename;
380380
t_stack_filename = MCdefaultstackptr -> getfilename();
381+
382+
// PM-2015-12-10: [[ Bug 16577 ]] If we are on a substack, use the parent stack filename
383+
if (MCStringIsEmpty(t_stack_filename))
384+
{
385+
MCStack *t_parent_stack;
386+
t_parent_stack = static_cast<MCStack *>(MCdefaultstackptr -> getparent());
387+
if (t_parent_stack != NULL)
388+
t_stack_filename = t_parent_stack -> getfilename();
389+
}
381390

382391
if (!MCStringLastIndexOfChar(t_stack_filename, '/', UINDEX_MAX, kMCStringOptionCompareExact, t_slash_index))
383392
t_slash_index = MCStringGetLength(t_stack_filename);

libfoundation/src/foundation-unicode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,7 @@ bool MCUnicodeWildcardMatch(const void *source_chars, uindex_t source_length, bo
22992299
{
23002300
// we're still ok if the current source grapheme falls within the appropriate range.
23012301
// If not, there may be other options within this pair of brackets
2302-
if (t_source_cp >= t_lower_limit || t_source_cp <= t_pattern_cp)
2302+
if (t_source_cp >= t_lower_limit && t_source_cp <= t_pattern_cp)
23032303
ok = true;
23042304
}
23052305
}
@@ -2347,8 +2347,6 @@ bool MCUnicodeWildcardMatch(const void *source_chars, uindex_t source_length, bo
23472347
// try and match the rest of the source string recursively.
23482348
while (t_source_filter -> HasData())
23492349
{
2350-
t_source_cp = t_source_filter -> GetNextCodepoint();
2351-
23522350
uindex_t t_sindex, t_pindex;
23532351
// if this is a candidate for a match, recurse.
23542352
if (t_source_cp == t_pattern_cp)
@@ -2380,6 +2378,7 @@ bool MCUnicodeWildcardMatch(const void *source_chars, uindex_t source_length, bo
23802378

23812379
// if we don't find a match, eat the source codepoint and continue.
23822380
t_source_filter -> AdvanceCursor();
2381+
t_source_cp = t_source_filter -> GetNextCodepoint();
23832382
}
23842383
}
23852384
return false;
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
script "CoreStringFilter"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
/*
20+
Filter wildcard special characters:
21+
* - matches any number of occurrences of any character
22+
? - matches a single occurrence of any character
23+
[abc] - matches any of a, b or c
24+
[a-m] - matches any lowercase character in the first half of the alphabet
25+
[!abc] - matches any character which is not a, b or c
26+
27+
The last three of these can be combined to create more complex character classes, for
28+
example [!abcA-C] - matches any character which is not a, b or c (upper or lower case)
29+
*/
30+
on __testFilterRangeAndOptions pIsNative, pLower, pMid, pUpper
31+
local tTestType
32+
if pIsNative then
33+
put "native" into tTestType
34+
else
35+
put "non-native" into tTestType
36+
end if
37+
38+
local tSource, tPattern
39+
40+
# Option tests
41+
put pLower into tSource
42+
put "[" & pLower & pMid & "]" into tPattern
43+
44+
filter tSource with tPattern
45+
TestAssert "filter with matching option pattern" && tTestType, tSource is pLower
46+
47+
put pUpper into tSource
48+
filter tSource with tPattern
49+
TestAssert "filter with non-matching option pattern" && tTestType, tSource is empty
50+
51+
put "[!" & pLower & pMid & "]" into tPattern
52+
put pUpper into tSource
53+
filter tSource with tPattern
54+
TestAssert "filter with matching negated option pattern" && tTestType, tSource is pUpper
55+
56+
# Range tests
57+
put pMid into tSource
58+
put "[" & pLower & "-" & pUpper & "]" into tPattern
59+
filter tSource with tPattern
60+
TestAssert "filter with match within range pattern" && tTestType, tSource is pMid
61+
62+
put pLower into tSource
63+
put "[" & pLower & "-" & pMid & "]" into tPattern
64+
filter tSource with tPattern
65+
TestAssert "filter with match on range pattern lower bound" && tTestType, tSource is pLower
66+
67+
put pMid into tSource
68+
filter tSource with tPattern
69+
TestAssert "filter with match on range pattern upper bound" && tTestType, tSource is pMid
70+
71+
put pUpper into tSource
72+
filter tSource with tPattern
73+
TestDiagnostic tSource
74+
TestAssert "filter with non-match outside range pattern" && tTestType, tSource is empty
75+
76+
put pUpper into tSource
77+
put "[!" & pLower & "-" & pMid & "]" into tPattern
78+
filter tSource with tPattern
79+
TestAssert "filter with match outside negated range pattern" && tTestType, tSource is pUpper
80+
81+
# Range options
82+
put pUpper into tSource
83+
put "[" & pLower & "-" & pMid & pLower & "-" & pUpper & "]" into tPattern
84+
filter tSource with tPattern
85+
TestAssert "filter with match within option range pattern" && tTestType, tSource is pUpper
86+
87+
# Range + options
88+
put pUpper into tSource
89+
put "[" & pLower & "-" & pMid & pLower & pMid & pUpper & "]" into tPattern
90+
filter tSource with tPattern
91+
TestAssert "filter with matching option after range pattern" && tTestType, tSource is pUpper
92+
end __testFilterRangeAndOptions
93+
94+
on __testFilterWildcard pIsNative, pString
95+
if pString is empty then
96+
TestFail "filter wildcard string not valid"
97+
exit __testFilterWildcard
98+
end if
99+
100+
# Single character wildcard
101+
local tSource, tPattern
102+
103+
put "?" into tPattern
104+
105+
if pIsNative then
106+
put return into tSource
107+
filter tSource with tPattern
108+
TestAssert "filter single char wildcard doesn't match empty", tSource is empty
109+
end if
110+
111+
local tTestType
112+
if pIsNative then
113+
put "native" into tTestType
114+
else
115+
put "non-native" into tTestType
116+
end if
117+
118+
local tChar
119+
put any char of pString into tChar
120+
121+
put tChar into tSource
122+
TestAssert "filter single char wildcard matches single char" && tTestType, tSource is tChar
123+
124+
put tChar & tChar into tSource
125+
filter tSource with tPattern
126+
TestAssert "filter single char wildcard doesn't match multiple chars" && tTestType, tSource is empty
127+
128+
put pString into tPattern
129+
put "?" into any char of tPattern
130+
put pString into tSource
131+
TestAssert "filter single char wildcard matches in string" && tTestType, tSource is pString
132+
133+
# Asterisk
134+
put "*" into tPattern
135+
136+
if pIsNative then
137+
put return into tSource
138+
filter tSource with tPattern
139+
TestAssert "filter asterisk matches empty", tSource is return
140+
end if
141+
142+
put pString into tSource
143+
filter tSource with tPattern
144+
TestAssert "filter asterisk matches mulitple chars" && tTestType, tSource is pString
145+
146+
put pString & "**" into tPattern
147+
put pString into tSource
148+
filter tSource with tPattern
149+
TestAssert "filter asterisks at end don't affect match" && tTestType, tSource is pString
150+
151+
put "*" & pString into tPattern
152+
put pString into tSource
153+
filter tSource with tPattern
154+
TestAssert "filter simple asterisk recursion" && tTestType, tSource is pString
155+
end __testFilterWildcard
156+
157+
on TestFilterWildcardNative
158+
__testFilterRangeAndOptions true, "a", "b", "c"
159+
__testFilterWildcard true, "abc"
160+
end TestFilterWildcardNative
161+
162+
on TestFilterWildcardNonNative
163+
local tGClef, tFClef, tCClef
164+
put numToCodepoint(0x1d11e) into tGClef
165+
put numToCodepoint(0x1d121) into tCClef
166+
put numToCodepoint(0x1d122) into tFClef
167+
168+
__testFilterRangeAndOptions false, tGClef, tCClef, tFClef
169+
__testFilterWildcard false, tGClef & tCClef & tFClef
170+
end TestFilterWildcardNonNative
171+
172+
on __testBug12644 pIsNative, pString
173+
local tTestType
174+
if pIsNative then
175+
put "native" into tTestType
176+
else
177+
put "non-native" into tTestType
178+
end if
179+
180+
local tSource, tPattern
181+
182+
put "*-U-*" into tPattern
183+
put "01-A-001" & pString into tSource
184+
185+
filter tSource with tPattern
186+
TestAssert "filter false positive bug 12644", tSource is empty
187+
end __testBug12644
188+
189+
on TestBug12644
190+
__testBug12644 true, "word"
191+
__testBug12644 false, "뤻뤼뤾"
192+
end TestBug12644
193+
194+
on __testBug16584 pIsNative, pString
195+
local tTestType
196+
if pIsNative then
197+
put "native" into tTestType
198+
else
199+
put "non-native" into tTestType
200+
end if
201+
202+
local tSource, tPattern
203+
204+
put pString into tPattern
205+
put "*" into char 1 of tPattern
206+
put "*" into char 3 to 5 of tPattern
207+
put pString into tSource
208+
209+
filter tSource with tPattern
210+
TestAssert "filter asterisk false negative bug 16584", tSource is pString
211+
end __testBug16584
212+
213+
on TestBug16584
214+
__testBug16584 true, "apple"
215+
__testBug16584 false, "뤻뤼뤼뤾룜"
216+
end TestBug16584

0 commit comments

Comments
 (0)