Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,14 @@ export class BaileysStartupService extends ChannelStartupService {
try {
const response = await axios.get(this.localProxy?.host);
const text = response.data;
const proxyUrls = text.split('\r\n');
const proxyUrls = text.split('\r\n').filter(Boolean);
Comment on lines 682 to +683
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use a more robust line-splitting strategy for different newline conventions.

Splitting only on "\r\n" assumes Windows line endings. If the list is served with Unix-style "\n" only, you’ll get a single, newline-containing entry and filter(Boolean) won’t fix it. Using something like text.split(/\r?\n/).filter(Boolean) will correctly handle both CRLF and LF cases.

Suggested change
const text = response.data;
const proxyUrls = text.split('\r\n');
const proxyUrls = text.split('\r\n').filter(Boolean);
const text = response.data;
const proxyUrls = text.split(/\r?\n/).filter(Boolean);

const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
const proxyUrl = 'http://' + proxyUrls[rand];
let proxyUrl = proxyUrls[rand];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Handle the case where the filtered proxy list is empty before picking a random entry.

With .filter(Boolean), proxyUrls can now be an empty array (e.g., blank/whitespace response). In that case Math.random() * 0 produces NaN, so proxyUrls[rand] is undefined and gets passed to makeProxyAgent. Please add a guard for proxyUrls.length === 0 and either skip proxy usage or log and fall back before computing rand.

// Si la línea ya tiene protocolo, úsala tal cual. Si no, anteponer el protocolo configurado
if (!/^\w+:\/\//.test(proxyUrl)) {
const proto = this.localProxy?.protocol?.replace(':', '') || 'http';
proxyUrl = `${proto}://${proxyUrl}`;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Protocol normalization may produce malformed URLs if the configured protocol includes ://.

If this.localProxy.protocol is set to values like 'http://' or 'http://:', using .replace(':', '') leaves proto as 'http//', yielding URLs like 'http///host:port'. Consider normalizing with something like protocol.replace(/:.*$/, ''), stripping :// explicitly, or enforcing a punctuation-free protocol value at config load time.

Suggested change
let proxyUrl = proxyUrls[rand];
// Si la línea ya tiene protocolo, úsala tal cual. Si no, anteponer el protocolo configurado
if (!/^\w+:\/\//.test(proxyUrl)) {
const proto = this.localProxy?.protocol?.replace(':', '') || 'http';
proxyUrl = `${proto}://${proxyUrl}`;
}
let proxyUrl = proxyUrls[rand];
// Si la línea ya tiene protocolo, úsala tal cual. Si no, anteponer el protocolo configurado
if (!/^\w+:\/\//.test(proxyUrl)) {
const rawProtocol = this.localProxy?.protocol?.trim();
const proto = rawProtocol ? rawProtocol.replace(/:.*$/, '') : 'http';
proxyUrl = `${proto}://${proxyUrl}`;
}

options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgentUndici(proxyUrl) };
} catch {
this.localProxy.enabled = false;
Expand Down