mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 18:43:02 +01:00
Fix regular expression value substitition in fbtrace.conf after macro substitition
Co-authored-by: Artyom Ivanov <artyom.ivanov@red-soft.ru>
This commit is contained in:
parent
2e4980bb21
commit
9f5b5bf5d4
@ -414,6 +414,41 @@ ConfigFile::LineType ConfigFile::parseLine(const char* fileName, const String& i
|
|||||||
* Substitute macro values in a string
|
* Substitute macro values in a string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned ConfigFile::getDirSeparatorLength(const String& value, size_t separatorPosition) const
|
||||||
|
{
|
||||||
|
if (separatorPosition >= value.length())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const char symbol = value[separatorPosition];
|
||||||
|
if (symbol == '/')
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (flags & REGEXP_SUPPORT && symbol == '\\')
|
||||||
|
{
|
||||||
|
// Check forward and backward for second backslash
|
||||||
|
if (separatorPosition + 1 < value.length() && value[separatorPosition + 1] == '\\')
|
||||||
|
return 2;
|
||||||
|
if (separatorPosition > 0 && value[separatorPosition - 1] == '\\')
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else if (symbol == '\\')
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigFile::adjustMacroReplacePositions(const String& value, const String& macro, String::size_type& from, String::size_type& to) const
|
||||||
|
{
|
||||||
|
if (macro.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Remove dir separators from value string if macro already contains them at start or end
|
||||||
|
if (macro[0] == PathUtils::dir_sep && from > 0)
|
||||||
|
from -= getDirSeparatorLength(value, from - 1);
|
||||||
|
if (macro[macro.length() - 1] == PathUtils::dir_sep)
|
||||||
|
to += getDirSeparatorLength(value, to);
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigFile::macroParse(String& value, const char* fileName) const
|
bool ConfigFile::macroParse(String& value, const char* fileName) const
|
||||||
{
|
{
|
||||||
String::size_type pos = 0;
|
String::size_type pos = 0;
|
||||||
@ -442,19 +477,21 @@ bool ConfigFile::macroParse(String& value, const char* fileName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avoid incorrect slashes in pathnames
|
// Avoid incorrect slashes in pathnames
|
||||||
PathUtils::fixupSeparators(value.begin());
|
|
||||||
PathUtils::fixupSeparators(macro.begin());
|
PathUtils::fixupSeparators(macro.begin());
|
||||||
|
|
||||||
if (subFrom > 0 && value[subFrom - 1] == PathUtils::dir_sep &&
|
if (flags & REGEXP_SUPPORT)
|
||||||
macro.length() > 0 && macro[0] == PathUtils::dir_sep)
|
|
||||||
{
|
{
|
||||||
--subFrom;
|
size_t pos = 0;
|
||||||
}
|
while ((pos = macro.find('\\', pos)) != String::npos)
|
||||||
if (subTo < value.length() && value[subTo] == PathUtils::dir_sep &&
|
|
||||||
macro.length() > 0 && macro[macro.length() - 1] == PathUtils::dir_sep)
|
|
||||||
{
|
{
|
||||||
++subTo;
|
macro.insert(pos, "\\");
|
||||||
|
pos += 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
PathUtils::fixupSeparators(value.begin());
|
||||||
|
|
||||||
|
adjustMacroReplacePositions(value, macro, subFrom, subTo);
|
||||||
|
|
||||||
// Now perform operation
|
// Now perform operation
|
||||||
value.replace(subFrom, subTo - subFrom, macro);
|
value.replace(subFrom, subTo - subFrom, macro);
|
||||||
|
@ -57,6 +57,7 @@ public:
|
|||||||
static const USHORT NATIVE_ORDER = 0x04;
|
static const USHORT NATIVE_ORDER = 0x04;
|
||||||
static const USHORT NO_COMMENTS = 0x08;
|
static const USHORT NO_COMMENTS = 0x08;
|
||||||
static const USHORT CUSTOM_MACROS = 0x10;
|
static const USHORT CUSTOM_MACROS = 0x10;
|
||||||
|
static const USHORT REGEXP_SUPPORT = 0x20;
|
||||||
|
|
||||||
// enum to distinguish ctors
|
// enum to distinguish ctors
|
||||||
enum UseText {USE_TEXT};
|
enum UseText {USE_TEXT};
|
||||||
@ -144,6 +145,8 @@ private:
|
|||||||
void include(const char* currentFileName, const Firebird::PathName& path);
|
void include(const char* currentFileName, const Firebird::PathName& path);
|
||||||
bool wildCards(const char* currentFileName, const Firebird::PathName& pathPrefix, FilesArray& components);
|
bool wildCards(const char* currentFileName, const Firebird::PathName& pathPrefix, FilesArray& components);
|
||||||
bool substituteStandardDir(const String& from, String& to) const;
|
bool substituteStandardDir(const String& from, String& to) const;
|
||||||
|
void adjustMacroReplacePositions(const String& value, const String& macro, String::size_type& from, String::size_type& to) const;
|
||||||
|
unsigned getDirSeparatorLength(const String& value, size_t subFrom) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONFIG_CONFIG_FILE_H
|
#endif // CONFIG_CONFIG_FILE_H
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "../../common/SimilarToRegex.h"
|
#include "../../common/SimilarToRegex.h"
|
||||||
#include "../../common/isc_f_proto.h"
|
#include "../../common/isc_f_proto.h"
|
||||||
#include "../../common/db_alias.h"
|
#include "../../common/db_alias.h"
|
||||||
|
#include "../../common/os/path_utils.h"
|
||||||
|
|
||||||
using namespace Firebird;
|
using namespace Firebird;
|
||||||
|
|
||||||
@ -46,6 +47,7 @@ void TraceCfgReader::readTraceConfiguration(const char* text,
|
|||||||
if (!found && el->name == #NAME) { \
|
if (!found && el->name == #NAME) { \
|
||||||
Firebird::PathName temp; \
|
Firebird::PathName temp; \
|
||||||
expandPattern(el, temp); \
|
expandPattern(el, temp); \
|
||||||
|
PathUtils::fixupSeparators(temp.begin()); \
|
||||||
m_config.NAME = temp.c_str(); \
|
m_config.NAME = temp.c_str(); \
|
||||||
found = true; \
|
found = true; \
|
||||||
}
|
}
|
||||||
@ -70,7 +72,8 @@ void TraceCfgReader::readTraceConfiguration(const char* text,
|
|||||||
|
|
||||||
void TraceCfgReader::readConfig()
|
void TraceCfgReader::readConfig()
|
||||||
{
|
{
|
||||||
ConfigFile cfgFile(ConfigFile::USE_TEXT, m_text, ConfigFile::HAS_SUB_CONF | ConfigFile::NATIVE_ORDER);
|
ConfigFile cfgFile(ConfigFile::USE_TEXT, m_text, ConfigFile::HAS_SUB_CONF | ConfigFile::NATIVE_ORDER
|
||||||
|
| ConfigFile::REGEXP_SUPPORT);
|
||||||
|
|
||||||
m_subpatterns[0].start = 0;
|
m_subpatterns[0].start = 0;
|
||||||
m_subpatterns[0].end = m_databaseName.length();
|
m_subpatterns[0].end = m_databaseName.length();
|
||||||
|
Loading…
Reference in New Issue
Block a user