Skip to content

Commit

Permalink
fix: user & object formatter to allow '/' in ids (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-jeffery authored Feb 28, 2024
1 parent a279701 commit 7d1ecb7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/src/openfga-yaml-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const undefinedTypeTuple = (user: string, instancePath: string) => {

// Format enforcement
const identifier = "[a-zA-Z0-9]([a-zA-Z0-9_-]*[a-zA-Z0-9])?";
const id = "[a-zA-Z0-9/_-]+";

const formatField = (field: string, regex: string, length: number) => {
if (!field.match(new RegExp(regex) || field.length > length)) {
Expand All @@ -133,15 +134,15 @@ const formatField = (field: string, regex: string, length: number) => {
};

function formatUser(user: string): boolean {
return formatField(user, `^${identifier}:(\\*|${identifier}(#${identifier})?)$`, 512);
return formatField(user, `^${identifier}:(\\*|${id}(#${identifier})?)$`, 512);
}

function formatRelation(relation: string): boolean {
return formatField(relation, `^${identifier}$`, 50);
}

function formatObject(object: string): boolean {
return formatField(object, `^${identifier}:${identifier}$`, 256);
return formatField(object, `^${identifier}:${id}$`, 256);
}

function formatCondition(condition: string): boolean {
Expand Down

0 comments on commit 7d1ecb7

Please sign in to comment.