forked from LBRYCommunity/lbry-sdk
fixed null claim name support for postgres
This commit is contained in:
parent
81926a42f9
commit
635aebfeeb
3 changed files with 14 additions and 14 deletions
|
@ -383,31 +383,24 @@ class BulkLoader:
|
||||||
row['claim_id'] = txo.claim_id
|
row['claim_id'] = txo.claim_id
|
||||||
row['claim_hash'] = txo.claim_hash
|
row['claim_hash'] = txo.claim_hash
|
||||||
try:
|
try:
|
||||||
claim_name = txo.claim_name
|
row['claim_name'] = txo.claim_name.replace('\x00', '')
|
||||||
if '\x00' in claim_name:
|
|
||||||
# log.error(f"Name for claim {txo.claim_id} contains a NULL (\\x00) character, skipping.")
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
row['claim_name'] = claim_name
|
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# log.error(f"Name for claim {txo.claim_id} contains invalid unicode, skipping.")
|
|
||||||
pass
|
pass
|
||||||
return row
|
return row
|
||||||
|
|
||||||
def claim_to_rows(self, txo: Output) -> Tuple[dict, List]:
|
def claim_to_rows(self, txo: Output) -> Tuple[dict, List]:
|
||||||
try:
|
try:
|
||||||
assert txo.claim_name
|
claim_name = txo.claim_name.replace('\x00', '')
|
||||||
assert txo.normalized_name
|
normalized_name = txo.normalized_name
|
||||||
except Exception:
|
except UnicodeDecodeError:
|
||||||
#self.logger.exception(f"Could not decode claim name for {tx.id}:{txo.position}.")
|
|
||||||
return {}, []
|
return {}, []
|
||||||
tx = txo.tx_ref.tx
|
tx = txo.tx_ref.tx
|
||||||
claim_hash = txo.claim_hash
|
claim_hash = txo.claim_hash
|
||||||
claim_record = {
|
claim_record = {
|
||||||
'claim_hash': claim_hash,
|
'claim_hash': claim_hash,
|
||||||
'claim_id': txo.claim_id,
|
'claim_id': txo.claim_id,
|
||||||
'claim_name': txo.claim_name,
|
'claim_name': claim_name,
|
||||||
'normalized': txo.normalized_name,
|
'normalized': normalized_name,
|
||||||
'address': txo.get_address(self.ledger),
|
'address': txo.get_address(self.ledger),
|
||||||
'txo_hash': txo.ref.hash,
|
'txo_hash': txo.ref.hash,
|
||||||
'amount': txo.amount,
|
'amount': txo.amount,
|
||||||
|
|
|
@ -44,7 +44,7 @@ URL_REGEX = _create_url_regex()
|
||||||
|
|
||||||
|
|
||||||
def normalize_name(name):
|
def normalize_name(name):
|
||||||
return unicodedata.normalize('NFD', name).casefold()
|
return unicodedata.normalize('NFD', name).casefold().replace('\x00', '')
|
||||||
|
|
||||||
|
|
||||||
class PathSegment(NamedTuple):
|
class PathSegment(NamedTuple):
|
||||||
|
|
|
@ -11,6 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input
|
||||||
from lbry.crypto.base58 import Base58
|
from lbry.crypto.base58 import Base58
|
||||||
from lbry.schema.claim import Stream, Channel
|
from lbry.schema.claim import Stream, Channel
|
||||||
from lbry.schema.support import Support
|
from lbry.schema.support import Support
|
||||||
|
from lbry.blockchain.script import OutputScript
|
||||||
from lbry.blockchain.lbrycrd import Lbrycrd
|
from lbry.blockchain.lbrycrd import Lbrycrd
|
||||||
from lbry.blockchain.sync import BlockchainSync
|
from lbry.blockchain.sync import BlockchainSync
|
||||||
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
||||||
|
@ -690,6 +691,12 @@ class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
|
||||||
claims = await search()
|
claims = await search()
|
||||||
self.assertEqual(0, len(claims))
|
self.assertEqual(0, len(claims))
|
||||||
|
|
||||||
|
async def test_null_claim_name(self):
|
||||||
|
await self.create_claim(name='\x00')
|
||||||
|
await self.generate(1)
|
||||||
|
empty_name, = await self.db.search_claims()
|
||||||
|
self.assertEqual('', empty_name.normalized_name)
|
||||||
|
|
||||||
async def test_short_and_canonical_urls(self):
|
async def test_short_and_canonical_urls(self):
|
||||||
search = self.db.search_claims
|
search = self.db.search_claims
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue