Skip to content

Commit 2477cd8

Browse files
committed
fix edge cases
1 parent 6ca21c0 commit 2477cd8

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

models/AgentRegistry.cfc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,23 @@ component singleton {
164164
return newContent
165165
}
166166

167-
var existingContent = fileRead( filePath )
167+
// Read existing content and locate markers
168+
var existingContent = fileRead( filePath ).trim()
168169
var startPos = findNoCase( startMarker, existingContent )
169170
var endPos = findNoCase( endMarker, existingContent )
170171

172+
// If existing content is empty or markers are not properly found, return new content as-is
173+
if ( !len( existingContent ) ) {
174+
return newContent
175+
}
176+
171177
// Old-format file (no marker pair) — write fresh content
172178
if ( !startPos || !endPos || endPos <= startPos ) {
173179
return newContent
174180
}
175181

176182
// Preserve user-authored content around managed section
177-
var userContentBeforeManaged = left( existingContent, startPos - 1 )
183+
var userContentBeforeManaged = startPos > 1 ? left( existingContent, startPos - 1 ) : ""
178184
var userStartPos = endPos + len( endMarker )
179185
var userContentAfterManaged = mid(
180186
existingContent,

0 commit comments

Comments
 (0)