diff --git a/.changeset/dry-impalas-serve.md b/.changeset/dry-impalas-serve.md
new file mode 100644
index 0000000000..3b1f502b9c
--- /dev/null
+++ b/.changeset/dry-impalas-serve.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-stack-overflow': patch
+---
+
+fix: fix decode issues in title and author fields in `StackOverflowSearchResultListItem`
diff --git a/plugins/stack-overflow/api-report.md b/plugins/stack-overflow/api-report.md
index 293c2ac226..7593db530f 100644
--- a/plugins/stack-overflow/api-report.md
+++ b/plugins/stack-overflow/api-report.md
@@ -10,7 +10,7 @@ import { BackstagePlugin } from '@backstage/core-plugin-api';
import { CardExtensionProps } from '@backstage/plugin-home-react';
import { JSX as JSX_2 } from 'react';
import { default as React_2 } from 'react';
-import { ResultHighlight } from '@backstage/plugin-search-common';
+import type { ResultHighlight } from '@backstage/plugin-search-common';
import { SearchResultListItemExtensionProps } from '@backstage/plugin-search-react';
// @public
diff --git a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
index 245666deeb..70e182b86d 100644
--- a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
+++ b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
@@ -15,7 +15,6 @@
*/
import React from 'react';
-import _unescape from 'lodash/unescape';
import { Link } from '@backstage/core-components';
import {
Divider,
@@ -26,8 +25,9 @@ import {
Chip,
} from '@material-ui/core';
import { useAnalytics } from '@backstage/core-plugin-api';
-import { ResultHighlight } from '@backstage/plugin-search-common';
+import type { ResultHighlight } from '@backstage/plugin-search-common';
import { HighlightedSearchResultText } from '@backstage/plugin-search-react';
+import { decodeHtml } from '../../util';
/**
* Props for {@link StackOverflowSearchResultListItem}
@@ -45,6 +45,7 @@ export const StackOverflowSearchResultListItem = (
props: StackOverflowSearchResultListItemProps,
) => {
const { result, highlight } = props;
+
const analytics = useAnalytics();
const handleClick = () => {
@@ -69,12 +70,12 @@ export const StackOverflowSearchResultListItem = (
{highlight?.fields?.title ? (
) : (
- _unescape(result.title)
+ decodeHtml(result.title)
)}
}
@@ -83,13 +84,13 @@ export const StackOverflowSearchResultListItem = (
<>
Author:{' '}
>
) : (
- `Author: ${result.text}`
+ `Author: ${decodeHtml(result.text)}`
)
}
/>
diff --git a/plugins/stack-overflow/src/util.ts b/plugins/stack-overflow/src/util.ts
new file mode 100644
index 0000000000..a40ae905ea
--- /dev/null
+++ b/plugins/stack-overflow/src/util.ts
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2024 The Backstage Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export function decodeHtml(input: string) {
+ const textContainer = document.createElement('textarea');
+ textContainer.innerHTML = input;
+ return textContainer.value;
+}