Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
805b57cd
Kaydet (Commit)
805b57cd
authored
Haz 06, 2014
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Various INetURLObject::getData() fixes
Change-Id: I5eafd6250bbde7227dcc0447a4280b7741c320de
üst
75e0fe06
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
23 deletions
+130
-23
test_urlobj.cxx
tools/qa/cppunit/test_urlobj.cxx
+90
-0
urlobj.cxx
tools/source/fsys/urlobj.cxx
+40
-23
No files found.
tools/qa/cppunit/test_urlobj.cxx
Dosyayı görüntüle @
805b57cd
...
...
@@ -12,6 +12,7 @@
#include <sal/types.h>
#include "cppunit/TestFixture.h"
#include <cppunit/extensions/HelperMacros.h>
#include <tools/stream.hxx>
#include <tools/urlobj.hxx>
#define OUSTR_TO_STDSTR( oustr ) std::string( OUStringToOString( oustr, RTL_TEXTENCODING_ASCII_US ).getStr() )
...
...
@@ -243,6 +244,94 @@ namespace tools_urlobj
}
}
void
urlobjTest_data
()
{
INetURLObject
url
;
SvMemoryStream
*
strm
;
unsigned
char
const
*
buf
;
url
=
INetURLObject
(
"data:"
);
//TODO: CPPUNIT_ASSERT(url.HasError());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
==
0
);
url
=
INetURLObject
(
"data:,"
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
0
),
strm
->
GetSize
());
delete
strm
;
url
=
INetURLObject
(
"data:,,%C3%A4%90"
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
4
),
strm
->
GetSize
());
buf
=
static_cast
<
unsigned
char
const
*>
(
strm
->
GetData
());
CPPUNIT_ASSERT_EQUAL
(
0x2C
,
int
(
buf
[
0
]));
CPPUNIT_ASSERT_EQUAL
(
0xC3
,
int
(
buf
[
1
]));
CPPUNIT_ASSERT_EQUAL
(
0xA4
,
int
(
buf
[
2
]));
CPPUNIT_ASSERT_EQUAL
(
0x90
,
int
(
buf
[
3
]));
delete
strm
;
url
=
INetURLObject
(
"data:base64,"
);
//TODO: CPPUNIT_ASSERT(url.HasError());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
==
0
);
url
=
INetURLObject
(
"data:;base64,"
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
0
),
strm
->
GetSize
());
delete
strm
;
url
=
INetURLObject
(
"data:;bAsE64,"
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
0
),
strm
->
GetSize
());
delete
strm
;
url
=
INetURLObject
(
"data:;base64,YWJjCg=="
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
4
),
strm
->
GetSize
());
buf
=
static_cast
<
unsigned
char
const
*>
(
strm
->
GetData
());
CPPUNIT_ASSERT_EQUAL
(
0x61
,
int
(
buf
[
0
]));
CPPUNIT_ASSERT_EQUAL
(
0x62
,
int
(
buf
[
1
]));
CPPUNIT_ASSERT_EQUAL
(
0x63
,
int
(
buf
[
2
]));
CPPUNIT_ASSERT_EQUAL
(
0x0A
,
int
(
buf
[
3
]));
delete
strm
;
url
=
INetURLObject
(
"data:;base64,YWJjCg="
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
==
0
);
url
=
INetURLObject
(
"data:;base64,YWJ$Cg=="
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
==
0
);
url
=
INetURLObject
(
"data:text/plain;param=%22;base64,%22,YQ=="
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
!=
0
);
CPPUNIT_ASSERT_EQUAL
(
sal_uIntPtr
(
4
),
strm
->
GetSize
());
buf
=
static_cast
<
unsigned
char
const
*>
(
strm
->
GetData
());
CPPUNIT_ASSERT_EQUAL
(
0x59
,
int
(
buf
[
0
]));
CPPUNIT_ASSERT_EQUAL
(
0x51
,
int
(
buf
[
1
]));
CPPUNIT_ASSERT_EQUAL
(
0x3D
,
int
(
buf
[
2
]));
CPPUNIT_ASSERT_EQUAL
(
0x3D
,
int
(
buf
[
3
]));
delete
strm
;
url
=
INetURLObject
(
"http://example.com"
);
CPPUNIT_ASSERT
(
!
url
.
HasError
());
strm
=
url
.
getData
();
CPPUNIT_ASSERT
(
strm
==
0
);
}
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
...
...
@@ -256,6 +345,7 @@ namespace tools_urlobj
CPPUNIT_TEST
(
urlobjTest_006
);
CPPUNIT_TEST
(
urlobjCmisTest
);
CPPUNIT_TEST
(
urlobjTest_emptyPath
);
CPPUNIT_TEST
(
urlobjTest_data
);
CPPUNIT_TEST_SUITE_END
(
);
};
// class createPool
...
...
tools/source/fsys/urlobj.cxx
Dosyayı görüntüle @
805b57cd
...
...
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <boost/checked_delete.hpp>
#include <o3tl/heap_ptr.hxx>
#include <tools/urlobj.hxx>
#include <tools/debug.hxx>
#include <tools/inetmime.hxx>
...
...
@@ -588,6 +592,21 @@ void INetURLObject::setInvalid()
m_aFragment
.
clear
();
}
namespace
{
SvMemoryStream
*
memoryStream
(
void
const
*
data
,
sal_Int32
length
)
{
o3tl
::
heap_ptr
<
char
,
boost
::
checked_array_deleter
<
char
>
>
b
(
new
char
[
length
]);
memcpy
(
b
.
get
(),
data
,
length
);
o3tl
::
heap_ptr
<
SvMemoryStream
>
s
(
new
SvMemoryStream
(
b
.
get
(),
length
,
STREAM_READ
));
s
->
ObjectOwnsMemory
(
true
);
b
.
release
();
return
s
.
release
();
}
}
SvMemoryStream
*
INetURLObject
::
getData
()
{
if
(
GetProtocol
()
!=
INET_PROT_DATA
)
...
...
@@ -596,34 +615,32 @@ SvMemoryStream* INetURLObject::getData()
}
OUString
sURLPath
=
GetURLPath
(
DECODE_WITH_CHARSET
,
RTL_TEXTENCODING_ISO_8859_1
);
OUString
sType
,
sSubType
;
OUString
sBase64Enc
(
";base64,"
);
INetContentTypeParameterList
params
;
sal_Unicode
const
*
pSkippedMediatype
=
INetMIME
::
scanContentType
(
sURLPath
.
getStr
(),
sURLPath
.
getStr
()
+
sURLPath
.
getLength
(),
&
sType
,
&
sSubType
,
&
params
);
sal_Int32
nCharactersSkipped
=
pSkippedMediatype
-
sURLPath
.
getStr
();
sal_Int32
nCommaIndex
=
sURLPath
.
indexOf
(
","
,
nCharactersSkipped
);
sal_Int32
nBase64Index
=
sURLPath
.
indexOf
(
sBase64Enc
,
nCharactersSkipped
);
SvMemoryStream
*
aStream
=
NULL
;
if
(
nBase64Index
>=
0
&&
nBase64Index
<
nCommaIndex
)
sal_Unicode
const
*
pSkippedMediatype
=
INetMIME
::
scanContentType
(
sURLPath
.
getStr
(),
sURLPath
.
getStr
()
+
sURLPath
.
getLength
(),
NULL
,
NULL
,
NULL
);
sal_Int32
nCharactersSkipped
=
pSkippedMediatype
==
NULL
?
0
:
pSkippedMediatype
-
sURLPath
.
getStr
();
if
(
sURLPath
.
match
(
","
,
nCharactersSkipped
))
{
nCharactersSkipped
+=
strlen
(
","
);
OString
sURLEncodedData
(
sURLPath
.
getStr
()
+
nCharactersSkipped
,
sURLPath
.
getLength
()
-
nCharactersSkipped
,
RTL_TEXTENCODING_ISO_8859_1
,
OUSTRING_TO_OSTRING_CVTFLAGS
);
return
memoryStream
(
sURLEncodedData
.
getStr
(),
sURLEncodedData
.
getLength
());
}
else
if
(
sURLPath
.
matchIgnoreAsciiCase
(
";base64,"
,
nCharactersSkipped
))
{
// base64 decoding
OUString
sBase64Data
=
sURLPath
.
copy
(
n
Base64Index
+
sBase64Enc
.
getLength
()
);
nCharactersSkipped
+=
strlen
(
";base64,"
);
OUString
sBase64Data
=
sURLPath
.
copy
(
n
CharactersSkipped
);
css
::
uno
::
Sequence
<
sal_Int8
>
aDecodedData
;
::
sax
::
Converter
::
decodeBase64
(
aDecodedData
,
sBase64Data
);
if
(
aDecodedData
.
hasElements
()
)
if
(
sax
::
Converter
::
decodeBase64SomeChars
(
aDecodedData
,
sBase64Data
)
==
sBase64Data
.
getLength
()
)
{
aStream
=
new
SvMemoryStream
(
aDecodedData
.
getArray
(),
aDecodedData
.
getLength
(),
STREAM_READ
);
return
memoryStream
(
aDecodedData
.
getArray
(),
aDecodedData
.
getLength
());
}
}
else
{
// URL decoding
OUString
sURLEncodedData
=
sURLPath
.
copy
(
nCommaIndex
+
1
);
aStream
=
new
SvMemoryStream
(
const_cast
<
sal_Char
*
>
(
OUStringToOString
(
sURLEncodedData
,
RTL_TEXTENCODING_UTF8
).
getStr
()),
sURLEncodedData
.
getLength
(),
STREAM_READ
);
}
return
aStream
;
return
NULL
;
}
namespace
unnamed_tools_urlobj
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment