Browse Source

Bug fix: Patterns in default values of extension options were escaped in an extension tooltip

Source commit: 3b912cbe2b229cee62b89dfc5e111d621dcb1332
Martin Prikryl 2 years ago
parent
commit
b0bd4dce29
2 changed files with 18 additions and 7 deletions
  1. 17 7
      source/windows/WinConfiguration.cpp
  2. 1 0
      source/windows/WinConfiguration.h

+ 17 - 7
source/windows/WinConfiguration.cpp

@@ -3571,16 +3571,22 @@ UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(
     {
       UnicodeString OptionKey = GetOptionKey(Option, Site);
       UnicodeString OptionValue;
+      bool NeedEscape;
       if (CustomCommandOptions->IndexOfName(OptionKey) >= 0)
       {
         OptionValue = CustomCommandOptions->Values[OptionKey];
+        NeedEscape = true;
       }
       else
       {
         OptionValue = Option.Default;
+        NeedEscape = !Option.CanHavePatterns(); // approximation only?
       }
       UnicodeString OptionCommand = GetOptionCommand(Option, OptionValue);
-      OptionCommand = TCustomCommand::Escape(OptionCommand);
+      if (NeedEscape)
+      {
+        OptionCommand = TCustomCommand::Escape(OptionCommand);
+      }
       Result = ReplaceText(Result, FORMAT(L"%%%s%%", (Option.Id)), OptionCommand);
     }
   }
@@ -3627,23 +3633,27 @@ bool __fastcall TCustomCommandType::TOption::GetIsControl() const
   return (Id != L"-");
 }
 //---------------------------------------------------------------------------
-bool TCustomCommandType::TOption::HasPatterns(TCustomCommand * CustomCommandForOptions) const
+bool TCustomCommandType::TOption::CanHavePatterns() const
 {
-  bool CanHavePatterns;
+  bool Result;
   switch (Kind)
   {
     case okTextBox:
     case okFile:
-      CanHavePatterns = true;
+      Result = true;
       break;
 
     default:
-      CanHavePatterns = false;
+      Result = false;
       break;
   }
-
+  return Result;
+}
+//---------------------------------------------------------------------------
+bool TCustomCommandType::TOption::HasPatterns(TCustomCommand * CustomCommandForOptions) const
+{
   bool Result =
-    CanHavePatterns &&
+    CanHavePatterns() &&
     FLAGSET(Flags, TCustomCommandType::ofRun) &&
     FLAGCLEAR(Flags, TCustomCommandType::ofConfig) &&
     CustomCommandForOptions->HasAnyPatterns(Default);

+ 1 - 0
source/windows/WinConfiguration.h

@@ -835,6 +835,7 @@ public:
 
     bool operator==(const TOption & Other) const;
     __property bool IsControl = { read = GetIsControl };
+    bool CanHavePatterns() const;
     bool HasPatterns(TCustomCommand * CustomCommandForOptions) const;
 
   private: