( baseDir: string, pluginId: string, version: string, )
| 138 | * @returns Absolute path to versioned plugin directory under baseDir |
| 139 | */ |
| 140 | export function getVersionedCachePathIn( |
| 141 | baseDir: string, |
| 142 | pluginId: string, |
| 143 | version: string, |
| 144 | ): string { |
| 145 | const { name: pluginName, marketplace } = parsePluginIdentifier(pluginId) |
| 146 | const sanitizedMarketplace = (marketplace || 'unknown').replace( |
| 147 | /[^a-zA-Z0-9\-_]/g, |
| 148 | '-', |
| 149 | ) |
| 150 | const sanitizedPlugin = (pluginName || pluginId).replace( |
| 151 | /[^a-zA-Z0-9\-_]/g, |
| 152 | '-', |
| 153 | ) |
| 154 | // Sanitize version to prevent path traversal attacks |
| 155 | const sanitizedVersion = version.replace(/[^a-zA-Z0-9\-_.]/g, '-') |
| 156 | return join( |
| 157 | baseDir, |
| 158 | 'cache', |
| 159 | sanitizedMarketplace, |
| 160 | sanitizedPlugin, |
| 161 | sanitizedVersion, |
| 162 | ) |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Get versioned cache path for a plugin under the primary plugins directory. |
no test coverage detected