Skip to content

Commit

Permalink
Merge branch 'master' into v5.13.x
Browse files Browse the repository at this point in the history
  • Loading branch information
scytacki committed Jul 22, 2024
2 parents 71bcbdc + 6e99051 commit 1f129b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/models/data/data-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ describe("data-types", () => {
"ccimg://fbrtdb.concord.org/hello.png",
"ccimg://fbrtdb.concord.org/anything.txt",
"ccimg://not-a-cc.domain.com/hello.png",
"random.string.com/"
"random.string.com/",
"curriculum/unitname/images/test.png",
"test/unit/images/test.png",
"test.png"
];
const testCases = valuesToTest.map(value => {
return [value, isImageUrl(value)];
Expand All @@ -168,6 +171,9 @@ describe("data-types", () => {
"ccimg://fbrtdb.concord.org/anything.txt" => true
"ccimg://not-a-cc.domain.com/hello.png" => false
"random.string.com/" => false
"curriculum/unitname/images/test.png" => true
"test/unit/images/test.png" => true
"test.png" => false
`);
});

Expand Down
3 changes: 2 additions & 1 deletion src/models/data/data-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function isImageUrl(val: IValueType) {
// The ImageMap has an isImageUrl function but it will pickup pretty much any http URL.
// And we don't want to add a dependency on the imageMap to this shared code.
const ccImagePattern = /^ccimg:\/\/fbrtdb\.concord\.org/;
const imageUrlPattern = /^(https?:\/\/.*\.(gif|jpg|jpeg|png)|data:image\/(gif|jpg|jpeg|png);base64,)/i;
const imageUrlPattern =
/(^(https?:\/\/)?[^:]*\/[^:]*\.(gif|jpg|jpeg|png)$)|(^data:image\/(gif|jpg|jpeg|png);base64,)/i;
return ccImagePattern.test(val) || imageUrlPattern.test(val);
}

0 comments on commit 1f129b8

Please sign in to comment.