-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove escaping all Python code, instead only escape strings
Previous attempt to support multi-line strings (#8) has escaped newline characters from entire Python code. After reconsidering the use case, single-line code only will be supported. However, the string values of the records might still contain new lines which has now been addressed when for selected records VAL fields only. Single quote escaping has also been fixed which closes #9 - double qoutes are not permitted by EPICS records unless they're escaped in the record already.
- Loading branch information
Vodopivec, Klemen
committed
Mar 21, 2021
1 parent
480b38a
commit 4b6afde
Showing
12 changed files
with
151 additions
and
37 deletions.
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
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
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
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
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
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
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
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
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,23 @@ | ||
# Makefile | ||
TOP = ../.. | ||
include $(TOP)/configure/CONFIG | ||
#---------------------------------------- | ||
# ADD MACRO DEFINITIONS AFTER THIS LINE | ||
|
||
USR_LDFLAGS += $(shell $(PYTHON_CONFIG) --ldflags) | ||
USR_CXXFLAGS += $(subst -Wstrict-prototypes,,$(shell $(PYTHON_CONFIG) --cflags)) | ||
USR_CXXFLAGS += -I$(TOP)/src | ||
USR_CXXFLAGS += -std=c++11 -g -ggdb -O0 | ||
SRC_DIRS += ../.. | ||
|
||
PROD_LIBS = Com | ||
|
||
TESTPROD_HOST = testutil | ||
testutil_SRCS += test_util.cpp | ||
testutil_SRCS += util.cpp | ||
TESTS += testutil | ||
|
||
TESTSCRIPTS_HOST = $(TESTS:%=%.t) | ||
|
||
include $(TOP)/configure/RULES | ||
|
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,96 @@ | ||
#include <util.h> | ||
|
||
#include <epicsUnitTest.h> | ||
#include <testMain.h> | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
struct TestEscape { | ||
static void newLine() | ||
{ | ||
testOk1(Util::escape("new\nline") == "new\\nline"); | ||
testOk1(Util::escape("one\ntwo\nthree") == "one\\ntwo\\nthree"); | ||
} | ||
|
||
static void singleQuote() | ||
{ | ||
testOk1(Util::escape("single ' quote") == "single \\' quote"); | ||
testOk1(Util::escape("embedded 'string'") == "embedded \\'string\\'"); | ||
testOk1(Util::escape("h'ello") == "h\\'ello"); | ||
} | ||
}; | ||
|
||
struct TestReplace { | ||
static void basic() | ||
{ | ||
const static std::map<std::string, std::string> fields = { | ||
{ "%VAL%", "hello" } | ||
}; | ||
testOk1(Util::replace("test string %VAL%", fields) == "test string hello"); | ||
testOk1(Util::replace("%VAL%", fields) == "hello"); | ||
testOk1(Util::replace("'%VAL%'", fields) == "'hello'"); | ||
} | ||
|
||
static void multipleInstances() | ||
{ | ||
const static std::map<std::string, std::string> fields = { | ||
{ "%VAL%", "hello" } | ||
}; | ||
testOk1(Util::replace("%VAL% %VAL%", fields) == "hello hello"); | ||
testOk1(Util::replace("%VAL%,%VAL%", fields) == "hello,hello"); | ||
testOk1(Util::replace("%VAL%/%VAL%/%VAL%", fields) == "hello/hello/hello"); | ||
} | ||
|
||
static void multipleFields() | ||
{ | ||
const static std::map<std::string, std::string> fields = { | ||
{ "%VAL%", "hello" }, | ||
{ "%NAME%", "Test:PV" }, | ||
{ "%HIGH%", "5" } | ||
}; | ||
testOk1(Util::replace("test string %VAL%", fields) == "test string hello"); | ||
testOk1(Util::replace("%NAME%=%VAL%", fields) == "Test:PV=hello"); | ||
testOk1(Util::replace("%NAME%: VAL=%VAL% HIGH=%HIGH%", fields) == "Test:PV: VAL=hello HIGH=5"); | ||
} | ||
|
||
static void singleChar() | ||
{ | ||
const static std::map<std::string, std::string> fields = { | ||
{ "\n", "\\n" }, | ||
{ "a", "b" }, | ||
{ "b", "c" }, | ||
}; | ||
testOk1(Util::replace("\n", fields) == "\\n"); | ||
testOk1(Util::replace("a", fields) == "b"); | ||
testOk1(Util::replace("aaa", fields) == "bbb"); | ||
testOk1(Util::replace("aba", fields) == "bcb"); | ||
} | ||
|
||
}; | ||
|
||
MAIN(testutil) | ||
{ | ||
testPlan(18); | ||
TestReplace::basic(); | ||
TestReplace::multipleInstances(); | ||
TestReplace::multipleFields(); | ||
TestReplace::singleChar(); | ||
TestEscape::newLine(); | ||
TestEscape::singleQuote(); | ||
/* | ||
testSetup(); | ||
logger_config_env(); | ||
Tester().loopback(false); | ||
Tester().loopback(true); | ||
Tester().lazy(); | ||
Tester().timeout(); | ||
Tester().cancel(); | ||
Tester().orphan(); | ||
TestPutBuilder().testSet(); | ||
testRO(); | ||
testError(); | ||
cleanup_for_valgrind(); | ||
*/ | ||
return testDone(); | ||
} |
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
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