Skip to content

Commit

Permalink
FIX: Messages with IDs starting with 66 and 67
Browse files Browse the repository at this point in the history
This fix addresses an issue in the encodeBinaryNode function where messages with IDs starting with "66" or "67" were being encoded incorrectly. The root cause was an improper order of checks in the writeString function, causing valid strings to be misinterpreted as hexadecimal values. This led to malformed nodes being generated and sent repeatedly, blocking message flows.

Changes:
Reordered checks in the writeString function to ensure:
Tokens are prioritized using TOKEN_MAP.
Nibble-encoded strings are processed correctly.
Valid strings default to JID decoding or raw encoding before hex checks.
Updated logic ensures accurate handling of IDs resembling hexadecimal strings but requiring string encoding.
Impact:
Resolves infinite ACK resend loops caused by malformed nodes.
Improves reliability in processing message acknowledgments.
Enhances network efficiency by eliminating unnecessary retries.
  • Loading branch information
vphelipe authored Jan 31, 2025
1 parent 3fca643 commit c39efc9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/WABinary/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ const encodeBinaryNodeInner = (
pushByte(tokenIndex.index)
} else if(isNibble(str)) {
writePackedBytes(str, 'nibble')
} else if(isHex(str)) {
writePackedBytes(str, 'hex')
} else if(str) {
const decodedJid = jidDecode(str)
if(decodedJid) {
writeJid(decodedJid)
} else {
writeStringRaw(str)
}
} else if(isHex(str)) {
writePackedBytes(str, 'hex')
}
}

Expand Down

0 comments on commit c39efc9

Please sign in to comment.