Skip to content

Commit c361372

Browse files
authored
Fix macOS Asset Visibility Issue in Local Version of RisuAI (#665)
# PR Checklist - [ ] Did you check if it works normally in all models? *ignore this when it dosen't uses models* - [x] Did you check if it works normally in all of web, local and node hosted versions? if it dosen't, did you blocked it in those versions? - [ ] Did you added a type def? # Description ## Problem This PR resolves an issue where assets were not visible on macOS when using `asset://localhost/` URLs. The problem occurred because **DOMPurify** was removing the `src` attribute when its value started with `asset://localhost/`. This behavior affected the visibility of assets on macOS for the Local version of RisuAI. ## Solution To address this, I chose to use `DOMPurify.addHook` to allow `src` attributes starting with `asset://localhost/` for certain tags. I also thought about another solution: passing `ALLOWED_URI_REGEXP` to `DOMPurify.sanitize`. However, I decided not to use it because it would require using regular expressions to check strings every time the method is called, which might be less efficient in my opinion. ## Considerations While this issue is specific to macOS and the Local version of RisuAI, I opted not to include additional conditions for the following reasons: 1. The code change is simple and lightweight. 2. It doesn’t cause conflicts on other OSes or RisuAI versions. 3. Avoiding conditions improves readability and maintainability. --- If you have any suggestions for a better approach, I’d be happy to hear them! --- ## Linked Issue This PR addresses and fixes #656
2 parents 871b9ce + 13fc50e commit c361372

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ts/parser.svelte.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {
7474
}
7575
})
7676

77+
DOMPurify.addHook('uponSanitizeAttribute', (node, data) => {
78+
if (['IMG', 'SOURCE', 'STYLE'].includes(node.nodeName) && data.attrName === 'src' && data.attrValue.startsWith('asset://localhost/')) {
79+
data.forceKeepAttr = true;
80+
}
81+
});
7782

7883
function renderMarkdown(md:markdownit, data:string){
7984
let quotes = ['“', '”', '‘', '’']
@@ -2278,4 +2283,4 @@ export function parseChatML(data:string):OpenAIChat[]|null{
22782283
content: v
22792284
}
22802285
})
2281-
}
2286+
}

0 commit comments

Comments
 (0)