Skip to content

Commit f0757ef

Browse files
author
Chris Elder
committed
[FAB-6738] GetState in CouchDB fails to return database
For a while composer has created composite keys in a specific format and this has worked fine. Since the introduction of a change to the GetState protocol, GetState has not been returning information. Additional investigation showed that the error occurs due to a bad URL generated when then key contains a colon ":" Problem is resolved by encoding the path using url EscapedPath() method instead of the String() method. Change-Id: I20ad8177301ea845dd234eb867c95b5cde7a908c Signed-off-by: Chris Elder <chris.elder@us.ibm.com>
1 parent 1e876e3 commit f0757ef

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

core/ledger/util/couchdb/couchdb.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,11 +1412,17 @@ func IsJSON(s string) bool {
14121412
// '+' is replaced by %2B, otherwise path encoding will ignore it, while CouchDB will unencode the plus as a space
14131413
// Note that all other URL special characters have been tested successfully without need for special handling
14141414
func encodePathElement(str string) string {
1415+
1416+
logger.Debugf("Entering encodePathElement() string=%s", str)
1417+
14151418
u := &url.URL{}
14161419
u.Path = str
1417-
encodedStr := u.String() // url encode using golang url path encoding rules
1420+
encodedStr := u.EscapedPath() // url encode using golang url path encoding rules
14181421
encodedStr = strings.Replace(encodedStr, "/", "%2F", -1)
14191422
encodedStr = strings.Replace(encodedStr, "+", "%2B", -1)
1423+
1424+
logger.Debugf("Exiting encodePathElement() encodedStr=%s", encodedStr)
1425+
14201426
return encodedStr
14211427
}
14221428

core/ledger/util/couchdb/couchdb_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ func TestDBBadConnectionDef(t *testing.T) {
111111

112112
}
113113

114+
func TestEncodePathElement(t *testing.T) {
115+
116+
encodedString := encodePathElement("testelement")
117+
testutil.AssertEquals(t, encodedString, "testelement")
118+
119+
encodedString = encodePathElement("test element")
120+
testutil.AssertEquals(t, encodedString, "test%20element")
121+
122+
encodedString = encodePathElement("/test element")
123+
testutil.AssertEquals(t, encodedString, "%2Ftest%20element")
124+
125+
encodedString = encodePathElement("/test element:")
126+
testutil.AssertEquals(t, encodedString, "%2Ftest%20element:")
127+
128+
encodedString = encodePathElement("/test+ element:")
129+
testutil.AssertEquals(t, encodedString, "%2Ftest%2B%20element:")
130+
131+
}
132+
114133
func TestBadCouchDBInstance(t *testing.T) {
115134

116135
//TODO continue changes to return and removal of sprintf in followon changes

0 commit comments

Comments
 (0)