Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions app/frontend/src/components/Answer/AnswerParser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type HtmlParsedAnswer = {

// Function to validate citation format and check if dataPoint starts with possible citation
function isCitationValid(contextDataPoints: any, citationCandidate: string): boolean {
const regex = /^[^\s]+\.[a-zA-Z0-9]+/;
const regex = /.+\.\w{1,}(?:#\S*)?$/;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


    // Regex to allow filenames with internal whitespace and a valid extension
    // .+          : Matches one or more of any character (including whitespace)
    // \.\w{1,}    : Matches a dot followed by one or more word characters (file extension)
    // (?:#\S*)?$  : Optionally matches a hash followed by zero or more non-whitespace characters until the end of the string

if (!regex.test(citationCandidate)) {
return false;
}
Expand All @@ -23,13 +23,11 @@ function isCitationValid(contextDataPoints: any, citationCandidate: string): boo
return false;
}

const isValidCitation = dataPointsArray.some(dataPoint => dataPoint.startsWith(citationCandidate));

if (!isValidCitation) {
return false;
}
const isValidCitation = dataPointsArray.some(dataPoint => {
return dataPoint.startsWith(citationCandidate);
});

return true;
return isValidCitation;
}

export function parseAnswerToHtml(answer: ChatAppResponse, isStreaming: boolean, onCitationClicked: (citationFilePath: string) => void): HtmlParsedAnswer {
Expand Down