@@ -3,59 +3,38 @@ import { afterEach, describe, expect, it } from 'vitest';
33import { sanitizeEnvValue , sanitizeProcessEnv } from '../../evals/shared/config.js' ;
44
55describe ( 'sanitizeEnvValue' , ( ) => {
6- it ( 'returns undefined for undefined ' , ( ) => {
6+ it ( 'passes through undefined and null ' , ( ) => {
77 expect ( sanitizeEnvValue ( undefined ) ) . toBeUndefined ( ) ;
8- } ) ;
9-
10- it ( 'returns null for null' , ( ) => {
118 expect ( sanitizeEnvValue ( null as unknown as undefined ) ) . toBeNull ( ) ;
129 } ) ;
1310
14- it ( 'strips trailing newline ' , ( ) => {
11+ it ( 'strips newlines and trims surrounding whitespace ' , ( ) => {
1512 expect ( sanitizeEnvValue ( 'sk-abc123\n' ) ) . toBe ( 'sk-abc123' ) ;
16- } ) ;
17-
18- it ( 'strips carriage-return + newline' , ( ) => {
1913 expect ( sanitizeEnvValue ( 'sk-abc123\r\n' ) ) . toBe ( 'sk-abc123' ) ;
20- } ) ;
21-
22- it ( 'strips embedded newlines' , ( ) => {
2314 expect ( sanitizeEnvValue ( 'sk-\nabc\r\n123\n' ) ) . toBe ( 'sk-abc123' ) ;
24- } ) ;
25-
26- it ( 'trims surrounding whitespace' , ( ) => {
2715 expect ( sanitizeEnvValue ( ' sk-abc123 ' ) ) . toBe ( 'sk-abc123' ) ;
2816 } ) ;
2917
30- it ( 'strips surrounding double quotes' , ( ) => {
31- expect ( sanitizeEnvValue ( '"sk-abc123"' ) ) . toBe ( 'sk-abc123' ) ;
18+ it ( 'strips control characters' , ( ) => {
19+ expect ( sanitizeEnvValue ( 'sk-abc\x00123' ) ) . toBe ( 'sk-abc123' ) ; // null byte
20+ expect ( sanitizeEnvValue ( 'sk-abc\x01123' ) ) . toBe ( 'sk-abc123' ) ; // SOH
21+ expect ( sanitizeEnvValue ( 'sk-abc\x0b123' ) ) . toBe ( 'sk-abc123' ) ; // vertical tab
22+ expect ( sanitizeEnvValue ( 'sk-abc\x0c123' ) ) . toBe ( 'sk-abc123' ) ; // form feed
23+ expect ( sanitizeEnvValue ( 'sk-abc\x1f123' ) ) . toBe ( 'sk-abc123' ) ; // unit separator
24+ expect ( sanitizeEnvValue ( 'sk-abc\x7f123' ) ) . toBe ( 'sk-abc123' ) ; // DEL
3225 } ) ;
3326
34- it ( 'strips only outer quotes (not inner)' , ( ) => {
27+ it ( 'strips surrounding double quotes only' , ( ) => {
28+ expect ( sanitizeEnvValue ( '"sk-abc123"' ) ) . toBe ( 'sk-abc123' ) ;
3529 expect ( sanitizeEnvValue ( '"sk-"abc"-123"' ) ) . toBe ( 'sk-"abc"-123' ) ;
36- } ) ;
37-
38- it ( 'does not strip single quotes' , ( ) => {
3930 expect ( sanitizeEnvValue ( "'sk-abc123'" ) ) . toBe ( "'sk-abc123'" ) ;
4031 } ) ;
4132
42- it ( 'handles combined whitespace, newlines, and quotes ' , ( ) => {
33+ it ( 'handles combined inputs and edge cases ' , ( ) => {
4334 expect ( sanitizeEnvValue ( ' "sk-abc123"\n' ) ) . toBe ( 'sk-abc123' ) ;
44- } ) ;
45-
46- it ( 'returns empty string for empty input' , ( ) => {
4735 expect ( sanitizeEnvValue ( '' ) ) . toBe ( '' ) ;
4836 } ) ;
4937
50- it ( 'strips control characters' , ( ) => {
51- expect ( sanitizeEnvValue ( 'sk-abc\x00123' ) ) . toBe ( 'sk-abc123' ) ; // null byte
52- expect ( sanitizeEnvValue ( 'sk-abc\x01123' ) ) . toBe ( 'sk-abc123' ) ; // SOH
53- expect ( sanitizeEnvValue ( 'sk-abc\x0b123' ) ) . toBe ( 'sk-abc123' ) ; // vertical tab
54- expect ( sanitizeEnvValue ( 'sk-abc\x0c123' ) ) . toBe ( 'sk-abc123' ) ; // form feed
55- expect ( sanitizeEnvValue ( 'sk-abc\x1f123' ) ) . toBe ( 'sk-abc123' ) ; // unit separator
56- expect ( sanitizeEnvValue ( 'sk-abc\x7f123' ) ) . toBe ( 'sk-abc123' ) ; // DEL
57- } ) ;
58-
5938 it ( 'is idempotent' , ( ) => {
6039 const value = ' "sk-abc123"\r\n' ;
6140 expect ( sanitizeEnvValue ( sanitizeEnvValue ( value ) ) ) . toBe ( sanitizeEnvValue ( value ) ) ;
0 commit comments