-
Notifications
You must be signed in to change notification settings - Fork 37
fix: Prevent context attributes from influencing judge template parsing #1258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
6eb9793
fad559c
fcc72ae
e8f9cf6
0294b26
f24a371
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| import Mustache from 'mustache'; | ||
|
|
||
| import { LDLogger } from '@launchdarkly/js-server-sdk-common'; | ||
|
|
||
| import { ChatResponse } from '../chat/types'; | ||
|
|
@@ -179,10 +177,13 @@ export class Judge { | |
| } | ||
|
|
||
| /** | ||
| * Interpolates message content with variables using Mustache templating. | ||
| * Use string replacement to prevent context attributes like {{=[ ]=}}) from | ||
| * influencing judge template parsing. | ||
| */ | ||
| private _interpolateMessage(content: string, variables: Record<string, string>): string { | ||
| return Mustache.render(content, variables, undefined, { escape: (item: any) => item }); | ||
| return content.replace(/\{\{(\w+)\}\}/g, (match, key) => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just want to make sure that we are okay with this matching since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct — |
||
| Object.prototype.hasOwnProperty.call(variables, key) ? variables[key] : match, | ||
| ); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.