aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2010-04-08 18:28:22 +0000
committerVincent Richard <[email protected]>2010-04-08 18:28:22 +0000
commit8f9fec339c395150fb52205d7337eb61348e2892 (patch)
tree218f7866813bdf50fb83d650e9ff865b09f11323
parentMigrated config script for newer versions of SCons. (diff)
downloadvmime-8f9fec339c395150fb52205d7337eb61348e2892.tar.gz
vmime-8f9fec339c395150fb52205d7337eb61348e2892.zip
Fixed parsing of non-significant whitespaces in field values.
-rw-r--r--src/parameterizedHeaderField.cpp26
-rw-r--r--tests/parser/parameterTest.cpp19
2 files changed, 42 insertions, 3 deletions
diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp
index 090d5b40..464990e9 100644
--- a/src/parameterizedHeaderField.cpp
+++ b/src/parameterizedHeaderField.cpp
@@ -85,12 +85,32 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty
const string::value_type* const pstart = buffer.data() + position;
const string::value_type* p = pstart;
- const string::size_type start = position;
+ // Skip non-significant whitespaces
+ string::size_type valueStart = position;
- while (p < pend && *p != ';') ++p;
+ while (p < pend && parserHelpers::isSpace(*p))
+ {
+ ++p;
+ ++valueStart;
+ }
+
+ // Advance up to ';', if any
+ string::size_type valueLength = 0;
+
+ while (p < pend && *p != ';') // FIXME: support ";" inside quoted or RFC-2047-encoded text
+ {
+ ++p;
+ ++valueLength;
+ }
+
+ // Trim whitespaces at the end of the value
+ while (valueLength > 0 && parserHelpers::isSpace(buffer[valueStart + valueLength - 1]))
+ --valueLength;
- getValue()->parse(buffer, start, position + (p - pstart));
+ // Parse value
+ getValue()->parse(buffer, valueStart, valueStart + valueLength);
+ // Reset parameters
removeAllParameters();
// If there is one or more parameters following...
diff --git a/tests/parser/parameterTest.cpp b/tests/parser/parameterTest.cpp
index 6d244381..803bb59a 100644
--- a/tests/parser/parameterTest.cpp
+++ b/tests/parser/parameterTest.cpp
@@ -36,6 +36,7 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST(testGenerate)
VMIME_TEST(testGenerateRFC2231)
VMIME_TEST(testNonStandardEncodedParam)
+ VMIME_TEST(testParseNonSignificantWS)
VMIME_TEST_LIST_END
@@ -53,6 +54,7 @@ VMIME_TEST_SUITE_BEGIN
};
+#define FIELD_VALUE(f) (f.getValue()->generate())
#define PARAM_VALUE(p, n) (p.getParameterAt(n)->getValue().generate())
#define PARAM_NAME(p, n) (p.getParameterAt(n)->getName())
#define PARAM_CHARSET(p, n) \
@@ -278,5 +280,22 @@ VMIME_TEST_SUITE_BEGIN
VASSERT_EQ("2.3", "Logo VMime.png", PARAM_VALUE(p2, 0));
}
+ // Parse parameters with non-significant whitespaces
+ void testParseNonSignificantWS()
+ {
+ parameterizedHeaderField p1;
+ p1.parse(" \t X \r\n");
+
+ VASSERT_EQ("1.1", "X", FIELD_VALUE(p1));
+
+ parameterizedHeaderField p2;
+ p2.parse(" X ; param1 = value1 \r\n");
+
+ VASSERT_EQ("2.1", 1, p2.getParameterCount());
+ VASSERT_EQ("2.2", "X", FIELD_VALUE(p2));
+ VASSERT_EQ("2.3", "param1", PARAM_NAME(p2, 0));
+ VASSERT_EQ("2.4", "value1", PARAM_VALUE(p2, 0));
+ }
+
VMIME_TEST_SUITE_END