-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added filename length restriction for debug mode (-srd flag) Issue-5929 #5931
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,6 +512,13 @@ func sanitizeFileName(fileName string) string { | |
} | ||
func (w *StandardWriter) WriteStoreDebugData(host, templateID, eventType string, data string) { | ||
if w.storeResponse { | ||
if len(host) > 60 { | ||
host = host[:57] + "..." | ||
} | ||
if len(templateID) > 100 { | ||
templateID = templateID[:97] + "..." | ||
} | ||
|
||
Comment on lines
+515
to
+521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider total filename length and OS limitations. The current implementation truncates +const (
+ // Common OS filename length limits
+ maxFilenameLength = 255 // typical limit for many filesystems
+ // Components
+ separatorLength = 1 // "_" separator
+ extensionLength = 4 // ".txt"
+)
func (w *StandardWriter) WriteStoreDebugData(host, templateID, eventType string, data string) {
if w.storeResponse {
+ // Calculate available space for host and templateID
+ availableLength := maxFilenameLength - separatorLength - extensionLength
+
+ // Distribute available length proportionally
+ hostRatio := 0.4 // 40% for host
+ templateIDRatio := 0.6 // 60% for templateID
+
+ maxHostLen := int(float64(availableLength) * hostRatio)
+ maxTemplateIDLen := int(float64(availableLength) * templateIDRatio)
+
if len(host) > maxHostLength {
host = host[:maxHostLength-ellipsisLength] + ellipsis
}
if len(templateID) > maxTemplateIDLength {
templateID = templateID[:maxTemplateIDLength-ellipsisLength] + ellipsis
}
+
+ // Ensure minimum length requirements
+ if len(host) < 1 || len(templateID) < 1 {
+ gologger.Warning().Msgf("Host or templateID too short after truncation: %s_%s", host, templateID)
+ }
|
||
filename := sanitizeFileName(fmt.Sprintf("%s_%s", host, templateID)) | ||
subFolder := filepath.Join(w.storeResponseDir, sanitizeFileName(eventType)) | ||
if !fileutil.FolderExists(subFolder) { | ||
|
@@ -526,7 +533,6 @@ func (w *StandardWriter) WriteStoreDebugData(host, templateID, eventType string, | |
_, _ = f.WriteString(fmt.Sprintln(data)) | ||
f.Close() | ||
} | ||
|
||
} | ||
|
||
// tryParseCause tries to parse the cause of given error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Extract magic numbers into named constants.
The hardcoded length limits and truncation points should be defined as package-level constants for better maintainability and clarity.
📝 Committable suggestion