Skip to content

Commit

Permalink
Escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jul 28, 2022
1 parent f23733b commit 6251025
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/metadata/helpers/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Escape(data []byte) []byte {
return data
}

data = escape.ReplaceAll(data, nil)
data = escape.ReplaceAll(data, []byte("\\$1"))
return bytes.Map(func(r rune) rune {
if unicode.IsPrint(r) || unicode.IsGraphic(r) {
return r
Expand Down
6 changes: 3 additions & 3 deletions cmd/metadata/helpers/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ func TestEscape(t *testing.T) {
{
name: "test 1",
data: []byte(`{"name":"πšƒπšžπš—πšπš›πšŠ π™Άπš•πš˜πš›πš’","decimals":0,"description":"πšƒπš‘πšŽ πššπšžπš’πšŽπšπš—πšŽπšœπšœ πšπš˜πšŽπšœπš—''𝚝 πš”πš’πš•πš• πšŠπš—πš’πš˜πš—\ud835, πš‹πšžπš πšπš‘πšŽ πšŒπšžπš›πš’πš˜πšœπš’πšπš’ 𝚍𝚘𝚎𝚜","artifactUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","displayUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","attributes":[{"name":"πš‚πš’πš£πšŽ","value":"πš‚πššπšžπšŠπš›πšŽ"},{"name":"π™±πšŠπšŒπš”πšπš›πš˜πšžπš—πš","value":"πš…πš˜πš’πš"},{"name":"πšƒπš’πš™πšŽ","value":"π™²πš˜πš•πš•πšŽπšŒπšπš’πš‹πš•πšŽ"},{"name":"π™΄πšπš’πšπš’πš˜πš—","value":"25"}],"formats":[{"mimeType":"image/jpeg","fileSize":1650550,"fileName":"UpperPix20220321_232739.jpg","uri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg"}]}`),
want: []byte(`{"name":"πšƒπšžπš—πšπš›πšŠ π™Άπš•πš˜πš›πš’","decimals":0,"description":"πšƒπš‘πšŽ πššπšžπš’πšŽπšπš—πšŽπšœπšœ πšπš˜πšŽπšœπš—''𝚝 πš”πš’πš•πš• πšŠπš—πš’πš˜πš—, πš‹πšžπš πšπš‘πšŽ πšŒπšžπš›πš’πš˜πšœπš’πšπš’ 𝚍𝚘𝚎𝚜","artifactUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","displayUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","attributes":[{"name":"πš‚πš’πš£πšŽ","value":"πš‚πššπšžπšŠπš›πšŽ"},{"name":"π™±πšŠπšŒπš”πšπš›πš˜πšžπš—πš","value":"πš…πš˜πš’πš"},{"name":"πšƒπš’πš™πšŽ","value":"π™²πš˜πš•πš•πšŽπšŒπšπš’πš‹πš•πšŽ"},{"name":"π™΄πšπš’πšπš’πš˜πš—","value":"25"}],"formats":[{"mimeType":"image/jpeg","fileSize":1650550,"fileName":"UpperPix20220321_232739.jpg","uri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg"}]}`),
want: []byte(`{"name":"πšƒπšžπš—πšπš›πšŠ π™Άπš•πš˜πš›πš’","decimals":0,"description":"πšƒπš‘πšŽ πššπšžπš’πšŽπšπš—πšŽπšœπšœ πšπš˜πšŽπšœπš—''𝚝 πš”πš’πš•πš• πšŠπš—πš’πš˜πš—\\ud835, πš‹πšžπš πšπš‘πšŽ πšŒπšžπš›πš’πš˜πšœπš’πšπš’ 𝚍𝚘𝚎𝚜","artifactUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","displayUri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg","attributes":[{"name":"πš‚πš’πš£πšŽ","value":"πš‚πššπšžπšŠπš›πšŽ"},{"name":"π™±πšŠπšŒπš”πšπš›πš˜πšžπš—πš","value":"πš…πš˜πš’πš"},{"name":"πšƒπš’πš™πšŽ","value":"π™²πš˜πš•πš•πšŽπšŒπšπš’πš‹πš•πšŽ"},{"name":"π™΄πšπš’πšπš’πš˜πš—","value":"25"}],"formats":[{"mimeType":"image/jpeg","fileSize":1650550,"fileName":"UpperPix20220321_232739.jpg","uri":"ipfs://QmbpyxoHBNWQvEATgdyy7VURZxAWZ5tYwSG56hseMe68ER/image.jpeg"}]}`),
}, {
name: "test 2",
data: []byte(`{"name": "Diplomat #2785", "symbol": "TZTOP", "formats": [{"uri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "mimeType": "image/png"}], "creators": ["tz1bKM4FRgAsGdDWzXs4o5HZdjBbLMbPBAA1"], "decimals": 0, "royalties": {"shares": {"tz1bKM4FRgAsGdDWzXs4o5HZdjBbLMbPBAA1": 6}, "decimals": 2}, "attributes": [{"name": "arm", "value": "Imitation Opal"}, {"name": "headdress", "value": "Face Guard"}, {"name": "katana", "value": "Uwan"}, {"name": "skin", "value": "Human Tan"}, {"name": "armor", "value": "Poor Man Armor"}, {"name": "backdrop", "value": "Grey Wave"}, {"name": "class", "value": "Commoner"}], "displayUri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "artifactUri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "description": "Diplomats of Tezotopia are more than a simple PFP collectible, these r@epresentatives unlock the ability to perform various diplomatic actions in the game.", "thumbnailUri": "ipfs://QmcSo4zgU8aASayU1FoVhsXVNicGch2NX2rJLHqELV4mc5", "isBooleanAmount": true}`),
want: []byte(`{"name": "Diplomat #2785", "symbol": "TZTOP", "formats": [{"uri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "mimeType": "image/png"}], "creators": ["tz1bKM4FRgAsGdDWzXs4o5HZdjBbLMbPBAA1"], "decimals": 0, "royalties": {"shares": {"tz1bKM4FRgAsGdDWzXs4o5HZdjBbLMbPBAA1": 6}, "decimals": 2}, "attributes": [{"name": "arm", "value": "Imitation Opal"}, {"name": "headdress", "value": "Face Guard"}, {"name": "katana", "value": "Uwan"}, {"name": "skin", "value": "Human Tan"}, {"name": "armor", "value": "Poor Man Armor"}, {"name": "backdrop", "value": "Grey Wave"}, {"name": "class", "value": "Commoner"}], "displayUri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "artifactUri": "ipfs://QmWynVS7dDChU4ZWikeJ5WkoWQtJw3mTYv2nuz9xgYobw5", "description": "Diplomats of Tezotopia are more than a simple PFP collectible, these r@epresentatives unlock the ability to perform various diplomatic actions in the game.", "thumbnailUri": "ipfs://QmcSo4zgU8aASayU1FoVhsXVNicGch2NX2rJLHqELV4mc5", "isBooleanAmount": true}`),
}, {
name: "test 3",
data: []byte(`{"name": "\u0005\u0001\u0000\u0000\u0000@339e27b6565ce3ffd5646f7b11070718bdeccc05333864da5aa3d1ed00a8a2cb"}`),
want: []byte(`{"name": "\u0005\u0001@339e27b6565ce3ffd5646f7b11070718bdeccc05333864da5aa3d1ed00a8a2cb"}`),
want: []byte(`{"name": "\u0005\u0001\\u0000\\u0000\\u0000@339e27b6565ce3ffd5646f7b11070718bdeccc05333864da5aa3d1ed00a8a2cb"}`),
}, {
name: "test 4",
data: []byte(`{"name": "\ud83e..."}`),
want: []byte(`{"name": "..."}`),
want: []byte(`{"name": "\\ud83e..."}`),
},
}
for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion cmd/metadata/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/dipdup-net/go-lib/prometheus"
"github.com/dipdup-net/metadata/cmd/metadata/helpers"
"github.com/dipdup-net/metadata/cmd/metadata/models"
"github.com/dipdup-net/metadata/internal/ipfs"
"github.com/go-pg/pg/v10"
Expand Down Expand Up @@ -138,7 +139,7 @@ func (s *Service[T]) manager(ctx context.Context) {
if s.ipfsRepo != nil {
if ipfsData, ok := resolvedIPFS[data[i].GetLink()]; ok {
data[i].SetStatus(models.StatusApplied)
data[i].SetMetadata(ipfsData.Data)
data[i].SetMetadata(helpers.Escape(ipfsData.Data))
data[i].IncrementRetryCount()
s.result <- data[i]
continue
Expand Down

0 comments on commit 6251025

Please sign in to comment.