-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix off-by-one in regex replace and add test (#2144)
Co-authored-by: amylizzle <[email protected]> Co-authored-by: wixoa <[email protected]>
- Loading branch information
1 parent
64c5684
commit 5483541
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var/models = "/obj/cable/brown{\n\ticon_state = \"2-8\"\n\t},\n/obj/cable/brown{\n\ticon_state = \"4-8\"\n\t},\n/turf/simulated/floor/orangeblack,\n/area/station/devzone" | ||
var/result_match = "/obj/cable/brown{\n\ticon_state = \"1\"\n\t},\n/obj/cable/brown{\n\ticon_state = \"2\"\n\t},\n/turf/simulated/floor/orangeblack,\n/area/station/devzone" | ||
|
||
/proc/RunTest() | ||
var/list/originalStrings = list() | ||
var/regex/noStrings = regex(@{"(["])(?:(?=(\\?))\2(.|\n))*?\1"}) | ||
var/stringIndex = 1 | ||
var/found | ||
do | ||
found = noStrings.Find(models, noStrings.next) | ||
if(found) | ||
var indexText = {""[stringIndex]""} | ||
stringIndex++ | ||
var match = copytext(noStrings.match, 2, -1) // Strip quotes | ||
models = noStrings.Replace(models, indexText, found) | ||
originalStrings[indexText] = (match) | ||
while(found) | ||
ASSERT(models == result_match) | ||
ASSERT(originalStrings ~= list("\"1\"" = "2-8", "\"2\"" = "4-8")) | ||
ASSERT(stringIndex == 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters