diff --git a/plugins/stack-overflow/package.json b/plugins/stack-overflow/package.json
index 73498e2a53..c1a4f8f40b 100644
--- a/plugins/stack-overflow/package.json
+++ b/plugins/stack-overflow/package.json
@@ -54,7 +54,6 @@
"@testing-library/jest-dom": "^6.0.0",
"@types/react": "^16.13.1 || ^17.0.0 || ^18.0.0",
"cross-fetch": "^4.0.0",
- "he": "^1.2.0",
"lodash": "^4.17.21",
"qs": "^6.9.4",
"react-use": "^17.2.4"
@@ -70,7 +69,6 @@
"@testing-library/dom": "^9.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
- "@types/he": "^1.2.3",
"msw": "^1.0.0"
},
"files": [
diff --git a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
index 9e98d6612f..70e182b86d 100644
--- a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
+++ b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx
@@ -27,7 +27,7 @@ import {
import { useAnalytics } from '@backstage/core-plugin-api';
import type { ResultHighlight } from '@backstage/plugin-search-common';
import { HighlightedSearchResultText } from '@backstage/plugin-search-react';
-import { decode } from 'he';
+import { decodeHtml } from '../../util';
/**
* Props for {@link StackOverflowSearchResultListItem}
@@ -45,13 +45,10 @@ export const StackOverflowSearchResultListItem = (
props: StackOverflowSearchResultListItemProps,
) => {
const { result, highlight } = props;
+
const analytics = useAnalytics();
const handleClick = () => {
- if (!result) {
- return;
- }
-
analytics.captureEvent('discover', result.title, {
attributes: { to: result.location },
value: props.rank,
@@ -73,12 +70,12 @@ export const StackOverflowSearchResultListItem = (
{highlight?.fields?.title ? (
) : (
- decode(result.title)
+ decodeHtml(result.title)
)}
}
@@ -87,13 +84,13 @@ export const StackOverflowSearchResultListItem = (
<>
Author:{' '}
>
) : (
- `Author: ${decode(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;
+}