Skip to content

Commit

Permalink
Make it so that when unrolling a seed packet, names are first santized.
Browse files Browse the repository at this point in the history
Without this, you could havea a let-multi that used a key of "komoroske.com:user_first_name" (as it's supposed to) but that's not a valid seed ID.

Should have been fixed in a925bdb

Part of #18. Part of #36.
  • Loading branch information
jkomoros committed Jul 4, 2023
1 parent 78558d7 commit 7c04811
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import {
Environment
} from './environment.js';
import { safeName } from './util.js';

//expandSeedData adds itself (and any sub-seeds) to the result. It returns the
//actual ID the seed decided on and registered itself with.
Expand Down Expand Up @@ -70,7 +71,7 @@ const expandSeedData = (idFromParent : SeedID, data : SeedData, result : Expande

const subSeedData = value as SeedData;

const subID = id + '-' + key;
const subID = id + '-' + safeName(key);
const actualSubID = expandSeedData(subID, subSeedData, result);

const subReference : SeedReference = {
Expand Down
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ const ILLEGAL_FILE_CHARS = /[\/\?<>\\:\*\|"]/g;
//Returns a filename like input but with characters that are illegal on mac stripped out.
export const safeFileName = (input : string) : string => {
return input.replace(ILLEGAL_FILE_CHARS, '_');
};

const ILLEGAL_NAME_CHARS = /[^a-zA-Z0-9_-]/g;

export const safeName = (input : string) : string => {
return input.replace(ILLEGAL_NAME_CHARS, '_');
};

0 comments on commit 7c04811

Please sign in to comment.