@@ -6,6 +6,7 @@ import { getBuckets } from "../utils/buckets";
66import { resolveOverriddenLocale } from "@lingo.dev/_spec" ;
77import createBucketLoader from "../loaders" ;
88import { minimatch } from "minimatch" ;
9+ import { safeDecode } from "../utils/key-matching" ;
910import { confirm } from "@inquirer/prompts" ;
1011
1112interface PurgeOptions {
@@ -123,10 +124,7 @@ export default new Command()
123124 if ( options . key ) {
124125 // minimatch for key patterns
125126 keysToRemove = Object . keys ( newData ) . filter ( ( k ) =>
126- minimatch (
127- decodeURIComponent ( k ) ,
128- decodeURIComponent ( options . key ! ) ,
129- ) ,
127+ minimatch ( safeDecode ( k ) , safeDecode ( options . key ! ) ) ,
130128 ) ;
131129 } else {
132130 // No key specified: remove all keys
@@ -136,7 +134,7 @@ export default new Command()
136134 // Show what will be deleted
137135 if ( options . key ) {
138136 bucketOra . info (
139- `About to delete ${ keysToRemove . length } key(s) matching '${ decodeURIComponent ( options . key ) } ' from ${ bucketPath . pathPattern } [${ targetLocale } ]:\n ${ keysToRemove . slice ( 0 , 10 ) . join ( ", " ) } ${ keysToRemove . length > 10 ? ", ..." : "" } ` ,
137+ `About to delete ${ keysToRemove . length } key(s) matching '${ safeDecode ( options . key ) } ' from ${ bucketPath . pathPattern } [${ targetLocale } ]:\n ${ keysToRemove . slice ( 0 , 10 ) . join ( ", " ) } ${ keysToRemove . length > 10 ? ", ..." : "" } ` ,
140138 ) ;
141139 } else {
142140 bucketOra . info (
@@ -164,7 +162,7 @@ export default new Command()
164162 await bucketLoader . push ( targetLocale , newData ) ;
165163 if ( options . key ) {
166164 bucketOra . succeed (
167- `Removed ${ keysToRemove . length } key(s) matching '${ decodeURIComponent ( options . key ) } ' from ${ bucketPath . pathPattern } [${ targetLocale } ]` ,
165+ `Removed ${ keysToRemove . length } key(s) matching '${ safeDecode ( options . key ) } ' from ${ bucketPath . pathPattern } [${ targetLocale } ]` ,
168166 ) ;
169167 } else {
170168 bucketOra . succeed (
@@ -173,7 +171,7 @@ export default new Command()
173171 }
174172 } else if ( options . key ) {
175173 bucketOra . info (
176- `No keys matching '${ decodeURIComponent ( options . key ) } ' found in ${ bucketPath . pathPattern } [${ targetLocale } ]` ,
174+ `No keys matching '${ safeDecode ( options . key ) } ' found in ${ bucketPath . pathPattern } [${ targetLocale } ]` ,
177175 ) ;
178176 } else {
179177 bucketOra . info ( "No keys to remove." ) ;
0 commit comments