diff --git a/autotest/gdrivers/pds.py b/autotest/gdrivers/pds.py index 29e0a5118fb8..196102de291e 100755 --- a/autotest/gdrivers/pds.py +++ b/autotest/gdrivers/pds.py @@ -315,4 +315,61 @@ def test_pds_band_storage_type_line_interleaved(): return tst.testOpen() +############################################################################### + +def test_pds_sharp_on_continuing_line(): + + gdal.FileFromMemBuffer('/vsimem/test', + """PDS_VERSION_ID = "PDS3" + +NOTE = (#9933FF, + #FFFF33) + +^IMAGE = 1 +OBJECT = IMAGE + BANDS = 1 + BAND_STORAGE_TYPE = "BAND SEQUENTIAL" + LINES = 1 + LINE_SAMPLES = 1 + SAMPLE_BITS = 8 + +END_OBJECT = IMAGE + +END +""") + + ds = gdal.Open('/vsimem/test') + + assert ds.GetMetadataItem('NOTE') == '(#9933FF,#FFFF33)' + + gdal.Unlink('/vsimem/test') + + +############################################################################### + +def test_pds_sharp_comma_continuing_line(): + + gdal.FileFromMemBuffer('/vsimem/test', + """PDS_VERSION_ID = "PDS3" + +NOTE = ("a" + ,"b") + +^IMAGE = 1 +OBJECT = IMAGE + BANDS = 1 + BAND_STORAGE_TYPE = "BAND SEQUENTIAL" + LINES = 1 + LINE_SAMPLES = 1 + SAMPLE_BITS = 8 + +END_OBJECT = IMAGE + +END +""") + + ds = gdal.Open('/vsimem/test') + + assert ds.GetMetadataItem('NOTE') == '("a","b")' + gdal.Unlink('/vsimem/test') diff --git a/gdal/frmts/pds/nasakeywordhandler.cpp b/gdal/frmts/pds/nasakeywordhandler.cpp index 2777f3b90a27..864c6934b07a 100644 --- a/gdal/frmts/pds/nasakeywordhandler.cpp +++ b/gdal/frmts/pds/nasakeywordhandler.cpp @@ -197,6 +197,18 @@ int NASAKeywordHandler::ReadGroup( const char *pszPathPrefix, CPLJSONObject &oCu } } +/************************************************************************/ +/* StripQuotesIfNeeded() */ +/************************************************************************/ + +static CPLString StripQuotesIfNeeded(const CPLString& osWord, + bool bQuotesAlreadyRemoved) +{ + if( bQuotesAlreadyRemoved || osWord.size() < 2 || osWord[0] != '"' ) + return osWord; + return osWord.substr(1, osWord.size() - 2); +} + /************************************************************************/ /* ReadPair() */ /* */ @@ -266,7 +278,7 @@ int NASAKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue, *pszHeaderNext == '{' || *pszHeaderNext == ')' || *pszHeaderNext == '}')) ) { - oArray.Add(osWord); + oArray.Add(StripQuotesIfNeeded(osWord, m_bStripSurroundingQuotes)); } } else if( CPLGetValueType(osWord) == CPL_VALUE_INTEGER ) @@ -279,6 +291,10 @@ int NASAKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue, } osValue += osWord; + while ( isspace( static_cast( *pszHeaderNext ) ) ) + { + pszHeaderNext++; + } if( *pszHeaderNext == ')' ) { @@ -312,6 +328,15 @@ int NASAKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue, { osValue += *pszHeaderNext; pszHeaderNext ++; + // Do not use SkipWhite() here to avoid being confuse by + // constructs like + // FOO = (#123456, + // #123456) + // where we could confuse the second line with a comment. + while ( isspace( static_cast( *pszHeaderNext ) ) ) + { + pszHeaderNext++; + } } SkipWhite(); @@ -339,7 +364,7 @@ int NASAKeywordHandler::ReadPair( CPLString &osName, CPLString &osValue, { if( bIsString ) { - oCur.Add( osName, osValue ); + oCur.Add( osName, StripQuotesIfNeeded(osValue, m_bStripSurroundingQuotes) ); } else if( CPLGetValueType(osValue) == CPL_VALUE_INTEGER ) {