Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
1a34ac03
Commit
1a34ac03
authored
Jan 15, 2016
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw a better exception when invalid base64 is detected in JSON
parent
730c38ad
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
JsonParserTest.cs
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
+9
-0
InvalidProtocolBufferException.cs
csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
+11
-0
JsonParser.cs
csharp/src/Google.Protobuf/JsonParser.cs
+7
-0
No files found.
csharp/src/Google.Protobuf.Test/JsonParserTest.cs
View file @
1a34ac03
...
@@ -821,6 +821,15 @@ namespace Google.Protobuf
...
@@ -821,6 +821,15 @@ namespace Google.Protobuf
Assert
.
Throws
<
InvalidProtocolBufferException
>(()
=>
parser63
.
Parse
<
TestRecursiveMessage
>(
data64
));
Assert
.
Throws
<
InvalidProtocolBufferException
>(()
=>
parser63
.
Parse
<
TestRecursiveMessage
>(
data64
));
}
}
[
Test
]
[
TestCase
(
"AQI"
)]
[
TestCase
(
"_-=="
)]
public
void
Bytes_InvalidBase64
(
string
badBase64
)
{
string
json
=
"{ \"singleBytes\": \""
+
badBase64
+
"\" }"
;
Assert
.
Throws
<
InvalidProtocolBufferException
>(()
=>
TestAllTypes
.
Parser
.
ParseJson
(
json
));
}
[
Test
]
[
Test
]
[
TestCase
(
"\"FOREIGN_BAR\""
)]
[
TestCase
(
"\"FOREIGN_BAR\""
)]
[
TestCase
(
"5"
)]
[
TestCase
(
"5"
)]
...
...
csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
View file @
1a34ac03
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
#endregion
using
System
;
using
System.IO
;
using
System.IO
;
namespace
Google.Protobuf
namespace
Google.Protobuf
...
@@ -45,6 +46,11 @@ namespace Google.Protobuf
...
@@ -45,6 +46,11 @@ namespace Google.Protobuf
{
{
}
}
internal
InvalidProtocolBufferException
(
string
message
,
Exception
innerException
)
:
base
(
message
,
innerException
)
{
}
internal
static
InvalidProtocolBufferException
MoreDataAvailable
()
internal
static
InvalidProtocolBufferException
MoreDataAvailable
()
{
{
return
new
InvalidProtocolBufferException
(
return
new
InvalidProtocolBufferException
(
...
@@ -82,6 +88,11 @@ namespace Google.Protobuf
...
@@ -82,6 +88,11 @@ namespace Google.Protobuf
"Protocol message contained an invalid tag (zero)."
);
"Protocol message contained an invalid tag (zero)."
);
}
}
internal
static
InvalidProtocolBufferException
InvalidBase64
(
Exception
innerException
)
{
return
new
InvalidProtocolBufferException
(
"Invalid base64 data"
,
innerException
);
}
internal
static
InvalidProtocolBufferException
InvalidEndTag
()
internal
static
InvalidProtocolBufferException
InvalidEndTag
()
{
{
return
new
InvalidProtocolBufferException
(
return
new
InvalidProtocolBufferException
(
...
...
csharp/src/Google.Protobuf/JsonParser.cs
View file @
1a34ac03
...
@@ -647,7 +647,14 @@ namespace Google.Protobuf
...
@@ -647,7 +647,14 @@ namespace Google.Protobuf
case
FieldType
.
String
:
case
FieldType
.
String
:
return
text
;
return
text
;
case
FieldType
.
Bytes
:
case
FieldType
.
Bytes
:
try
{
return
ByteString
.
FromBase64
(
text
);
return
ByteString
.
FromBase64
(
text
);
}
catch
(
FormatException
e
)
{
throw
InvalidProtocolBufferException
.
InvalidBase64
(
e
);
}
case
FieldType
.
Int32
:
case
FieldType
.
Int32
:
case
FieldType
.
SInt32
:
case
FieldType
.
SInt32
:
case
FieldType
.
SFixed32
:
case
FieldType
.
SFixed32
:
...
...
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