mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: failed to send message to self, add checks for empty strings and invalid nodes (#1322)
* fix: failed to send message to self, add checks for empty strings and invalid nodes * fix: update nibble and hex checks to handle optional string parameters
This commit is contained in:
committed by
GitHub
parent
d5dc758874
commit
bca5102819
@@ -149,8 +149,8 @@ const encodeBinaryNodeInner = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isNibble = (str: string) => {
|
const isNibble = (str?: string) => {
|
||||||
if(str.length > TAGS.PACKED_MAX) {
|
if(!str || str.length > TAGS.PACKED_MAX) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +164,8 @@ const encodeBinaryNodeInner = (
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const isHex = (str: string) => {
|
const isHex = (str?: string) => {
|
||||||
if(str.length > TAGS.PACKED_MAX) {
|
if(!str || str.length > TAGS.PACKED_MAX) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +179,12 @@ const encodeBinaryNodeInner = (
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const writeString = (str: string) => {
|
const writeString = (str?: string) => {
|
||||||
|
if(str === undefined || str === null) {
|
||||||
|
pushByte(TAGS.LIST_EMPTY)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const tokenIndex = TOKEN_MAP[str]
|
const tokenIndex = TOKEN_MAP[str]
|
||||||
if(tokenIndex) {
|
if(tokenIndex) {
|
||||||
if(typeof tokenIndex.dict === 'number') {
|
if(typeof tokenIndex.dict === 'number') {
|
||||||
@@ -212,7 +217,11 @@ const encodeBinaryNodeInner = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validAttributes = Object.keys(attrs).filter(k => (
|
if(!tag) {
|
||||||
|
throw new Error('Invalid node: tag cannot be undefined')
|
||||||
|
}
|
||||||
|
|
||||||
|
const validAttributes = Object.keys(attrs || {}).filter(k => (
|
||||||
typeof attrs[k] !== 'undefined' && attrs[k] !== null
|
typeof attrs[k] !== 'undefined' && attrs[k] !== null
|
||||||
))
|
))
|
||||||
|
|
||||||
@@ -232,8 +241,10 @@ const encodeBinaryNodeInner = (
|
|||||||
writeByteLength(content.length)
|
writeByteLength(content.length)
|
||||||
pushBytes(content)
|
pushBytes(content)
|
||||||
} else if(Array.isArray(content)) {
|
} else if(Array.isArray(content)) {
|
||||||
writeListStart(content.length)
|
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string')
|
||||||
for(const item of content) {
|
)
|
||||||
|
writeListStart(validContent.length)
|
||||||
|
for(const item of validContent) {
|
||||||
encodeBinaryNodeInner(item, opts, buffer)
|
encodeBinaryNodeInner(item, opts, buffer)
|
||||||
}
|
}
|
||||||
} else if(typeof content === 'undefined') {
|
} else if(typeof content === 'undefined') {
|
||||||
|
|||||||
Reference in New Issue
Block a user