File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ import (
21
21
"github.com/microsoft/typescript-go/internal/tspath"
22
22
)
23
23
24
+ // isValidSliceRange checks if the given start and end indices are valid for slicing a string/slice of the given length.
25
+ func isValidSliceRange (start , end , length int ) bool {
26
+ return start >= 0 && end >= 0 && start <= end && end <= length
27
+ }
28
+
24
29
type SymbolExportInfo struct {
25
30
symbol * ast.Symbol
26
31
moduleSymbol * ast.Symbol
@@ -120,7 +125,7 @@ func (e *exportInfoMap) add(
120
125
121
126
// Bounds check to prevent slice bounds out of range panic
122
127
fileName := moduleFile .FileName ()
123
- if topLevelPackageNameIndex + 1 >= 0 && packageRootIndex >= 0 && topLevelPackageNameIndex + 1 <= packageRootIndex && packageRootIndex <= len (fileName ) {
128
+ if isValidSliceRange ( topLevelPackageNameIndex + 1 , packageRootIndex , len (fileName ) ) {
124
129
packageName = module .UnmangleScopedPackageName (modulespecifiers .GetPackageNameFromTypesPackageName (fileName [topLevelPackageNameIndex + 1 : packageRootIndex ]))
125
130
}
126
131
You can’t perform that action at this time.
0 commit comments