Clarification on quoting for wxFileConfig Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MortenMacFly
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Feb 09, 2006 8:13 am

Clarification on quoting for wxFileConfig

Post by MortenMacFly »

I would like to understand how quoting for

Code: Select all

wxFileConfig
works.
I would like to save values (RegEx) like this in a INI file (thats the chosen format):

Code: Select all

my_regex=\s+height=".*?"
However, this screws the INI file on write and obviously on next load. It seems that the issue is with missing quotes.
I would like to know if the

Code: Select all

wxFileConfig
API is supposed to handle proper quoting itself or if the developer has to take care by converting the content to be saved to e.g.:

Code: Select all

my_reg=\s+height=\".*?\"
...instead. Alternatively, is there any kind of flag should set ta I simply did not find?

What is the proper handling of such cases? I am using wxWidgets 3.0.3 (Linux) and 3.2.1 (Windows).
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Clarification on quoting for wxFileConfig

Post by doublemax »

If you actually use wxFileConfig to write that entry, it is responsible for escaping the string properly (unless you explicitly set the wxCONFIG_USE_NO_ESCAPE_CHARACTERS flag). If it doesn't, it's a bug.

Can you show some code some that reproduces the issue?
Use the source, Luke!
MortenMacFly
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Feb 09, 2006 8:13 am

Re: Clarification on quoting for wxFileConfig

Post by MortenMacFly »

doublemax wrote: Sun Feb 05, 2023 11:06 am Can you show some code some that reproduces the issue?
Its not something special that is implemented. I think its really related to just that type string:

Code: Select all

\s+height=".*?"
The code to write that entry is this line (in a class that derived from wxFileConfig):

Code: Select all

       Write(wxString::Format(wxT("/RegEx%lu"), static_cast<unsigned long>(num)), reg_ex);
...with reg_ex being the string that is grabbed from a wxTextControl field using GetValue().

I see that in the INI file this line is added in that case:

Code: Select all

RegEx49=\\s+height=".*?"
...here you can see: The backslash is escaped but then all other characters that better should be escaped, too aren't. Is this related to this equality sign in the string? Because note that there are two of them: One coming from Property=Value and another one from the string which isn't escaped, to.

So the class does some escaping but then stops?!
MortenMacFly
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Feb 09, 2006 8:13 am

Re: Clarification on quoting for wxFileConfig

Post by MortenMacFly »

I've forgotten to mention: Reproducibility is tricky for me as the effect happens on a customers site, not mine. Therefore I was asking if I do something wrong in general. But since I have not setup this flag you mentioned it actually should work just fine... shouldn't it?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Clarification on quoting for wxFileConfig

Post by doublemax »

I can't reproduce it with this code:

Code: Select all

{
  wxFileConfig f("", "", wxT("d:\\_test.ini") );
  f.SetPath( "/" );

  wxString regex( wxT("\\s+height=\".*?\"") );
  wxLogMessage("regex before: %s", regex);
  f.Write( "regex1", regex );
  f.Flush();
}

{
  wxFileConfig f("", "", wxT("d:\\_test.ini") );
  f.SetPath( "/" );

  wxString regex = f.Read("regex1");
  wxLogMessage("regex after: %s", regex);
}
The resulting line in the .INI file is identical to yours.
Use the source, Luke!
MortenMacFly
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Feb 09, 2006 8:13 am

Re: Clarification on quoting for wxFileConfig

Post by MortenMacFly »

doublemax wrote: Sun Feb 05, 2023 12:02 pm I can't reproduce it with this code:
[...]
The resulting line in the .INI file is identical to yours.
OK, I am afraid I don't know whats going on here. I see from a screen-grabber video on the customers PC that the INI file gets screwed but I also cannot reproduce. The only difference is that the customer has a Windows 7 environment.

However, you helped me anyway by confirming that this is actually not an issue - or at least not a wxWidgets / wrong API usage issue.

So thank you very much!
Post Reply