Date: prev next · Thread: first prev next last
2014 Archives by date, by thread · List index


Let me shamelessly misuse this opportunity to campaign for a likely little-known feature of the rtl string starts/endsWith family of functions that can take an additional "rest" out parameter that gets assigned the remainder of the input iff the input matches.

That is, the code from the two commits below could boil down to something like

  OUString aColorStr(aValue);
  if (!aColorStr.startsWithIgnoreAsciiCase("rgb(", &aColorStr)
      || !aColorStr.endsWith(")", &aColorStr)
      || aColorStr.isEmpty())
  {
      break;
  }

(Is this feature too subtle? Likely; but I didn't find a cooler way to add it.)

Stephan


On 02/17/2014 09:08 PM, Jan Holesovsky wrote:
  sw/source/filter/html/parcss1.cxx |   12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)

New commits:
commit 3ecdc23d164d8e8632375247604cddf04f1e4df4
Author: Jan Holesovsky <kendy@collabora.com>
Date:   Mon Feb 17 21:00:03 2014 +0100

     Let's not parse nonsensical data.

     Change-Id: Icf956c3824286e8244cf5809be88568de0d6a068

diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
index 8489355..692474b 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -1273,11 +1273,11 @@ sal_Bool CSS1Expression::GetColor( Color &rColor ) const
          {
              sal_uInt8 aColors[3] = { 0, 0, 0 };

-            OSL_ENSURE( aValue.startsWithIgnoreAsciiCase( "rgb" ) &&
-                        aValue.getLength() > 5 &&
-                        '(' == aValue[3] &&
-                        ')' == aValue[aValue.getLength()-1],
-                        "keine gueltiges RGB(...)" );
+            if (!aValue.startsWithIgnoreAsciiCase( "rgb" ) || aValue.getLength() < 6 ||
+                    aValue[3] != '(' || aValue[aValue.getLength()-1] != ')')
+            {
+                break;
+            }

              OUString aColorStr(aValue.copy(4, aValue.getLength() - 5));

commit 2afb605601ec0b29e177dd38e4f16bfe06590882
Author: Jan Holesovsky <kendy@collabora.com>
Date:   Mon Feb 17 20:49:24 2014 +0100

     Fix crash in css rgb color handling.

     Crashing since 2000 (or earlier).

     Change-Id: I9f91d56f380be2421370b0acbee351461e1f0973

diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx
index 3dfbaea..8489355 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -1279,7 +1279,7 @@ sal_Bool CSS1Expression::GetColor( Color &rColor ) const
                          ')' == aValue[aValue.getLength()-1],
                          "keine gueltiges RGB(...)" );

-            OUString aColorStr( aValue.copy( 4, aValue.getLength()-1 ) );
+            OUString aColorStr(aValue.copy(4, aValue.getLength() - 5));

              sal_Int32 nPos = 0;
              sal_uInt16 nCol = 0;



Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.