Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
a0f119fa
Commit
a0f119fa
authored
Oct 09, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1811 from ForrestWeston/master
Added an xml decoder, Fixes #1612
parents
9cfa23ee
6e243521
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
15 deletions
+78
-15
core/commands/object.go
core/commands/object.go
+25
-1
test/sharness/t0051-object-data/brokenPut.xml
test/sharness/t0051-object-data/brokenPut.xml
+1
-0
test/sharness/t0051-object-data/testPut.xml
test/sharness/t0051-object-data/testPut.xml
+1
-0
test/sharness/t0051-object.sh
test/sharness/t0051-object.sh
+51
-14
No files found.
core/commands/object.go
View file @
a0f119fa
...
...
@@ -3,6 +3,7 @@ package commands
import
(
"bytes"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
...
...
@@ -689,7 +690,7 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
// check that we have data in the Node to add
// otherwise we will add the empty object without raising an error
if
n
ode
.
Data
==
""
&&
len
(
node
.
Links
)
==
0
{
if
N
ode
Empty
(
node
)
{
return
nil
,
ErrEmptyNode
}
...
...
@@ -701,6 +702,24 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
case
objectEncodingProtobuf
:
dagnode
,
err
=
dag
.
Decoded
(
data
)
case
objectEncodingXML
:
node
:=
new
(
Node
)
err
=
xml
.
Unmarshal
(
data
,
node
)
if
err
!=
nil
{
return
nil
,
err
}
// check that we have data in the Node to add
// otherwise we will add the empty object without raising an error
if
NodeEmpty
(
node
)
{
return
nil
,
ErrEmptyNode
}
dagnode
,
err
=
deserializeNode
(
node
)
if
err
!=
nil
{
return
nil
,
err
}
default
:
return
nil
,
ErrUnknownObjectEnc
}
...
...
@@ -725,6 +744,7 @@ type objectEncoding string
const
(
objectEncodingJSON
objectEncoding
=
"json"
objectEncodingProtobuf
=
"protobuf"
objectEncodingXML
=
"xml"
)
func
getObjectEnc
(
o
interface
{})
objectEncoding
{
...
...
@@ -779,3 +799,7 @@ func deserializeNode(node *Node) (*dag.Node, error) {
return
dagnode
,
nil
}
func
NodeEmpty
(
node
*
Node
)
bool
{
return
(
node
.
Data
==
""
&&
len
(
node
.
Links
)
==
0
)
}
test/sharness/t0051-object-data/brokenPut.xml
0 → 100644
View file @
a0f119fa
<Noodles><Spaghetti>
This is not a valid dag object fail
</Spaghetti></Noodles>
test/sharness/t0051-object-data/testPut.xml
0 → 100644
View file @
a0f119fa
<Node><Data>
Test xml for sharness test
</Data></Node>
test/sharness/t0051-object.sh
View file @
a0f119fa
...
...
@@ -32,25 +32,25 @@ test_object_cmd() {
printf "Hello Mars" >expected_in &&
ipfs add expected_in >actual_Addout
'
test_expect_success
"'ipfs add testData' output looks good"
'
HASH="QmWkHFpYBZ9mpPRreRbMhhYWXfUhBAue3JkbbpFqwowSRb" &&
echo "added $HASH expected_in" >expected_Addout &&
test_cmp expected_Addout actual_Addout
'
test_expect_success
"'ipfs object get' succeeds"
'
ipfs object get $HASH >actual_getOut
'
test_expect_success
"'ipfs object get' output looks good"
'
test_cmp ../t0051-object-data/expected_getOut actual_getOut
'
test_expect_success
"'ipfs object stat' succeeds"
'
ipfs object stat $HASH >actual_stat
'
test_expect_success
"'ipfs object get' output looks good"
'
echo "NumLinks: 0" > expected_stat &&
echo "BlockSize: 18" >> expected_stat &&
...
...
@@ -63,47 +63,84 @@ test_object_cmd() {
test_expect_success
"'ipfs object put file.json' succeeds"
'
ipfs object put ../t0051-object-data/testPut.json > actual_putOut
'
test_expect_success
"'ipfs object put file.json' output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putOut &&
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put file.xml' succeeds"
'
ipfs object put ../t0051-object-data/testPut.xml --inputenc=xml > actual_putOut
'
test_expect_success
"'ipfs object put file.xml' output looks good"
'
HASH="QmQzNKUHy4HyEUGkqKe3q3t796ffPLQXYCkHCcXUNT5JNK" &&
printf "added $HASH" > expected_putOut &&
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put' from stdin succeeds"
'
cat ../t0051-object-data/testPut.xml | ipfs object put --inputenc=xml > actual_putStdinOut
'
test_expect_success
"'ipfs object put broken.xml' should fail"
'
test_expect_code 1 ipfs object put ../t0051-object-data/brokenPut.xml --inputenc=xml 2>actual_putBrokenErr >actual_putBroken
'
test_expect_success
"'ipfs object put broken.hxml' output looks good"
'
touch expected_putBroken &&
printf "Error: no data or links in this node\n" > expected_putBrokenErr &&
test_cmp expected_putBroken actual_putBroken &&
test_cmp expected_putBrokenErr actual_putBrokenErr
'
test_expect_success
"'ipfs object get --enc=xml' succeeds"
'
ipfs object get --enc=xml $HASH >utf8_xml
'
test_expect_success
"'ipfs object put --inputenc=xml' succeeds"
'
ipfs object put --inputenc=xml <utf8_xml >actual
'
test_expect_failure
"'ipfs object put --inputenc=xml' output looks good"
'
echo "added $HASH" >expected &&
test_cmp expected actual
'
test_expect_success
"'ipfs object put file.pb' succeeds"
'
ipfs object put --inputenc=protobuf ../t0051-object-data/testPut.pb > actual_putOut
'
test_expect_success
"'ipfs object put file.pb' output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putOut &&
test_cmp expected_putOut actual_putOut
'
test_expect_success
"'ipfs object put' from stdin succeeds"
'
cat ../t0051-object-data/testPut.json | ipfs object put > actual_putStdinOut
'
test_expect_success
"'ipfs object put' from stdin output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putStdinOut &&
test_cmp expected_putStdinOut actual_putStdinOut
'
test_expect_success
"'ipfs object put' from stdin (pb) succeeds"
'
cat ../t0051-object-data/testPut.pb | ipfs object put --inputenc=protobuf > actual_putPbStdinOut
'
test_expect_success
"'ipfs object put' from stdin (pb) output looks good"
'
HASH="QmUTSAdDi2xsNkDtLqjFgQDMEn5di3Ab9eqbrt4gaiNbUD" &&
printf "added $HASH" > expected_putStdinOut &&
test_cmp expected_putStdinOut actual_putPbStdinOut
'
test_expect_success
"'ipfs object put broken.json' should fail"
'
test_expect_code 1 ipfs object put ../t0051-object-data/brokenPut.json 2>actual_putBrokenErr >actual_putBroken
'
test_expect_success
"'ipfs object put broken.hjson' output looks good"
'
touch expected_putBroken &&
printf "Error: no data or links in this node\n" > expected_putBrokenErr &&
...
...
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