@@ -5,6 +5,7 @@ import type { OpenClawConfig } from "../config/config.js";
55import {
66 normalizeLowercaseStringOrEmpty ,
77 normalizeOptionalLowercaseString ,
8+ normalizeOptionalString ,
89} from "../shared/string-coerce.js" ;
910import { normalizeStringEntries } from "../shared/string-normalization.js" ;
1011import {
@@ -256,7 +257,7 @@ function buildProviderAllowFromResolution(params: {
256257
257258function describeAllowFromResolutionError ( err : unknown ) : string {
258259 if ( err instanceof Error ) {
259- const name = err . name . trim ( ) ;
260+ const name = normalizeOptionalString ( err . name ) ?? "" ;
260261 return name || "Error" ;
261262 }
262263 return "unknown_error" ;
@@ -275,7 +276,7 @@ function resolveOwnerAllowFromList(params: {
275276 }
276277 const filtered : string [ ] = [ ] ;
277278 for ( const entry of raw ) {
278- const trimmed = String ( entry ?? "" ) . trim ( ) ;
279+ const trimmed = normalizeOptionalString ( String ( entry ?? "" ) ) ?? "" ;
279280 if ( ! trimmed ) {
280281 continue ;
281282 }
@@ -466,7 +467,7 @@ function shouldUseFromAsSenderFallback(params: {
466467 from ?: string | null ;
467468 chatType ?: string | null ;
468469} ) : boolean {
469- const from = ( params . from ?? "" ) . trim ( ) ;
470+ const from = normalizeOptionalString ( params . from ) ?? "" ;
470471 if ( ! from ) {
471472 return false ;
472473 }
@@ -490,7 +491,7 @@ function resolveSenderCandidates(params: {
490491 const { plugin, cfg, accountId } = params ;
491492 const candidates : string [ ] = [ ] ;
492493 const pushCandidate = ( value ?: string | null ) => {
493- const trimmed = ( value ?? "" ) . trim ( ) ;
494+ const trimmed = normalizeOptionalString ( value ) ?? "" ;
494495 if ( ! trimmed ) {
495496 return ;
496497 }
@@ -527,7 +528,7 @@ function resolveFallbackAllowFrom(params: {
527528 providerId ?: ChannelId ;
528529 accountId ?: string | null ;
529530} ) : Array < string | number > {
530- const providerId = params . providerId ?. trim ( ) ;
531+ const providerId = normalizeOptionalString ( params . providerId ) ;
531532 if ( ! providerId ) {
532533 return [ ] ;
533534 }
@@ -629,8 +630,8 @@ export function resolveCommandAuthorization(params: {
629630 cfg ,
630631 ) ;
631632 const plugin = providerId ? getChannelPlugin ( providerId ) : undefined ;
632- const from = ( ctx . From ?? "" ) . trim ( ) ;
633- const to = ( ctx . To ?? "" ) . trim ( ) ;
633+ const from = normalizeOptionalString ( ctx . From ) ?? "" ;
634+ const to = normalizeOptionalString ( ctx . To ) ?? "" ;
634635 const commandsAllowFromConfigured = Boolean (
635636 cfg . commands ?. allowFrom && typeof cfg . commands . allowFrom === "object" ,
636637 ) ;
0 commit comments