Skip to content

Commit 62ff35f

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

File tree

1 file changed

+13
-10
lines changed
  • platform/view/services/db/driver/sql/common

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"runtime/debug"
1515
"strings"
16+
"unicode/utf8"
1617

1718
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1819
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
@@ -277,25 +278,27 @@ func (db *VaultPersistence) UpdateStatusesValid(txIDs []driver.TxID, offset int)
277278
return query, params
278279
}
279280

281+
const minUnicodeRuneValue = string(0)
282+
const maxUnicodeRuneValue = string(utf8.MaxRune)
280283
const forbiddenRune = "\x00"
281-
const forbiddenRuneReplacement = "??"
284+
285+
var replacements = map[string]string{
286+
minUnicodeRuneValue: "?0?",
287+
maxUnicodeRuneValue: "?1?",
288+
forbiddenRune: "?2?",
289+
}
282290

283291
// TODO: Better sanitization of inputs
284292
func escape(s string) (string, error) {
285-
if strings.HasPrefix(s, forbiddenRune) {
286-
logger.Infof("Escaping [%s]", s)
287-
s = forbiddenRuneReplacement + strings.TrimPrefix(s, forbiddenRune)
288-
}
289-
if strings.Contains(s, forbiddenRune) {
290-
return "", errors.Errorf("invalid character in [%s]", s)
293+
for forbidden, replacement := range replacements {
294+
s = strings.ReplaceAll(s, forbidden, replacement)
291295
}
292296
return s, nil
293297
}
294298

295299
func unescape(s string) string {
296-
if strings.HasPrefix(s, forbiddenRuneReplacement) {
297-
logger.Infof("Reverting escaped [%s]", s)
298-
return forbiddenRune + strings.TrimPrefix(s, forbiddenRuneReplacement)
300+
for forbidden, replacement := range replacements {
301+
s = strings.ReplaceAll(s, replacement, forbidden)
299302
}
300303
return s
301304
}

0 commit comments

Comments
 (0)