Skip to content

Commit

Permalink
MITAB: Disable table fields "laundering" for non-neutral charset
Browse files Browse the repository at this point in the history
  • Loading branch information
drons committed Jun 25, 2024
1 parent 2afacf4 commit b30dab2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ogr/ogrsf_frmts/mitab/mitab_tabfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ int TABFile::WriteTABFile()
if (strlen(GetEncoding()) > 0)
osFieldName.Recode(CPL_ENC_UTF8, GetEncoding());

char *pszCleanName = TABCleanFieldName(osFieldName);
char *pszCleanName =
TABCleanFieldName(osFieldName, GetEncoding());
osFieldName = pszCleanName;
CPLFree(pszCleanName);

Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/mitab/mitab_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ char *TABEscapeString(char *pszString)
*
* The returned string should be freed by the caller.
**********************************************************************/
char *TABCleanFieldName(const char *pszSrcName)
char *TABCleanFieldName(const char *pszSrcName, const char *pszEncoding)
{
char *pszNewName = CPLStrdup(pszSrcName);
if (strlen(pszNewName) > 31)
Expand All @@ -481,6 +481,7 @@ char *TABCleanFieldName(const char *pszSrcName)
// It was also verified that extended chars with accents are also
// accepted.
int numInvalidChars = 0;
bool bNeutralCharset = (pszEncoding == nullptr || strlen(pszEncoding) == 0);
for (int i = 0; pszSrcName && pszSrcName[i] != '\0'; i++)
{
if (pszSrcName[i] == '#')
Expand All @@ -493,7 +494,7 @@ char *TABCleanFieldName(const char *pszSrcName)
}
else if (!(pszSrcName[i] == '_' ||
(i != 0 && pszSrcName[i] >= '0' && pszSrcName[i] <= '9') ||
(pszSrcName[i] >= 'a' && pszSrcName[i] <= 'z') ||
(!bNeutralCharset || (pszSrcName[i] >= 'a' && pszSrcName[i] <= 'z') ||
(pszSrcName[i] >= 'A' && pszSrcName[i] <= 'Z') ||
static_cast<GByte>(pszSrcName[i]) >= 192))
{
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/mitab/mitab_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ char **TAB_CSLLoad(const char *pszFname);
char *TABEscapeString(char *pszString);
char *TABUnEscapeString(char *pszString, GBool bSrcIsConst);

char *TABCleanFieldName(const char *pszSrcName);
char *TABCleanFieldName(const char *pszSrcName, const char *pszCharset);

const char *TABUnitIdToString(int nId);
int TABUnitIdFromString(const char *pszName);
Expand Down

0 comments on commit b30dab2

Please sign in to comment.