Skip to content

Commit b061157

Browse files
temp!
Signed-off-by: Alexandros Filios <alexandros.filios@ibm.com>
1 parent 62ff35f commit b061157

File tree

1 file changed

+19
-21
lines changed
  • platform/view/services/db/driver/sql/common

1 file changed

+19
-21
lines changed

platform/view/services/db/driver/sql/common/vault.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
"fmt"
1414
"runtime/debug"
1515
"strings"
16-
"unicode/utf8"
1716

1817
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1918
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
2019
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
2120
driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver"
21+
"golang.org/x/text/encoding/unicode"
2222
)
2323

2424
type VaultTables struct {
@@ -278,29 +278,24 @@ func (db *VaultPersistence) UpdateStatusesValid(txIDs []driver.TxID, offset int)
278278
return query, params
279279
}
280280

281-
const minUnicodeRuneValue = string(0)
282-
const maxUnicodeRuneValue = string(utf8.MaxRune)
283-
const forbiddenRune = "\x00"
281+
// const minUnicodeRuneValue = string(0)
282+
// const maxUnicodeRuneValue = string(utf8.MaxRune)
283+
// const forbiddenRune = "\x00"
284+
//
285+
// var replacements = map[string]string{
286+
// minUnicodeRuneValue: "?0?",
287+
// maxUnicodeRuneValue: "?1?",
288+
// forbiddenRune: "?2?",
289+
// }
290+
var encoder = unicode.UTF8.NewEncoder()
291+
var decoder = unicode.UTF8.NewDecoder()
284292

285-
var replacements = map[string]string{
286-
minUnicodeRuneValue: "?0?",
287-
maxUnicodeRuneValue: "?1?",
288-
forbiddenRune: "?2?",
289-
}
290-
291-
// TODO: Better sanitization of inputs
292293
func escape(s string) (string, error) {
293-
for forbidden, replacement := range replacements {
294-
s = strings.ReplaceAll(s, forbidden, replacement)
295-
}
296-
return s, nil
294+
return encoder.String(s)
297295
}
298296

299-
func unescape(s string) string {
300-
for forbidden, replacement := range replacements {
301-
s = strings.ReplaceAll(s, replacement, forbidden)
302-
}
303-
return s
297+
func unescape(s string) (string, error) {
298+
return decoder.String(s)
304299
}
305300

306301
func convertStateRows(writes driver.Writes, metaWrites driver.MetaWrites) ([]stateRow, error) {
@@ -443,6 +438,9 @@ func (it *TxStateIterator) Next() (*driver.VersionedRead, error) {
443438
if err != nil {
444439
return nil, err
445440
}
446-
r.Key = unescape(r.Key)
441+
r.Key, err = unescape(r.Key)
442+
if err != nil {
443+
return nil, err
444+
}
447445
return &r, nil
448446
}

0 commit comments

Comments
 (0)