cozy-search 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,22 +11,13 @@ var _react = _interopRequireDefault(require("react"));
11
11
 
12
12
  var _Markdown = _interopRequireDefault(require("cozy-ui/transpiled/react/Markdown"));
13
13
 
14
- /**
15
- * Sanitize chat content by removing special sources tags like
16
- * [REF]...[/REF] or [doc_X] that are not currently handled.
17
- *
18
- * @param {string} content - content to sanitize
19
- * @returns {string} sanitized content
20
- */
21
- var sanitizeContent = function sanitizeContent(content) {
22
- return content.replace(/\s?\[REF\][\s\S]*?\[\/REF\]/g, '').replace(/\s?\[doc_\d+\]/g, '');
23
- };
14
+ var _helpers = require("../helpers");
24
15
 
25
16
  var ChatItemLabel = function ChatItemLabel(_ref) {
26
17
  var label = _ref.label;
27
- var content = sanitizeContent(label);
28
18
 
29
19
  if (typeof label === 'string') {
20
+ var content = (0, _helpers.sanitizeChatContent)(label);
30
21
  return /*#__PURE__*/_react.default.createElement(_Markdown.default, {
31
22
  content: content
32
23
  });
@@ -3,3 +3,4 @@ export function makeConversationId(): string;
3
3
  export function pushMessagesIdInState(id: any, res: any, setState: any): void;
4
4
  export function isMessageForThisConversation(res: any, messagesId: any): any;
5
5
  export function isAssistantEnabled(): any;
6
+ export function sanitizeChatContent(content: string): string;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.pushMessagesIdInState = exports.makeConversationId = exports.isMessageForThisConversation = exports.isAssistantEnabled = exports.getInstantMessage = void 0;
8
+ exports.sanitizeChatContent = exports.pushMessagesIdInState = exports.makeConversationId = exports.isMessageForThisConversation = exports.isAssistantEnabled = exports.getInstantMessage = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -54,5 +54,26 @@ exports.isMessageForThisConversation = isMessageForThisConversation;
54
54
  var isAssistantEnabled = function isAssistantEnabled() {
55
55
  return (0, _cozyFlags.default)('cozy.assistant.enabled');
56
56
  };
57
+ /**
58
+ * Sanitize chat content by removing special sources tags like
59
+ * [REF]...[/REF] or [doc_X] that are not currently handled.
60
+ *
61
+ * @param {string} content - content to sanitize
62
+ * @returns {string} sanitized content
63
+ */
64
+
65
+
66
+ exports.isAssistantEnabled = isAssistantEnabled;
67
+
68
+ var sanitizeChatContent = function sanitizeChatContent(content) {
69
+ if (!content) {
70
+ return '';
71
+ }
72
+
73
+ return content // Remove REFdoc_1/REF
74
+ .replace(/\s?\[REF\][\s\S]*?\[\/REF\]/g, '') // Remove [REF]doc_1[/REF]
75
+ .replace(/\s?REF[\s\S]*?\/REF/g, '') // remove « [doc_1] »
76
+ .replace(/\s?\[doc_\d+\]/g, '');
77
+ };
57
78
 
58
- exports.isAssistantEnabled = isAssistantEnabled;
79
+ exports.sanitizeChatContent = sanitizeChatContent;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _helpers = require("./helpers");
4
+
5
+ describe('sanitizeChatContent', function () {
6
+ it('should return empty string for empty content', function () {
7
+ expect((0, _helpers.sanitizeChatContent)('')).toBe('');
8
+ expect((0, _helpers.sanitizeChatContent)(null)).toBe('');
9
+ expect((0, _helpers.sanitizeChatContent)(undefined)).toBe('');
10
+ });
11
+ it('should return string if no special tags', function () {
12
+ var text = 'How you doing, here no ref.';
13
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe(text);
14
+ });
15
+ it('should remove tags REF.../REF', function () {
16
+ var text = 'Before REFdoc_1/REF after';
17
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe('Before after');
18
+ });
19
+ it('should remove tags [REF]...[/REF]', function () {
20
+ var text = 'Before [REF]doc_1[/REF] after';
21
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe('Before after');
22
+ });
23
+ it('should remove mixed REF tags ', function () {
24
+ var text = 'A REF.../REF B [REF]...[/REF] C REF.../REF D';
25
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe('A B C D');
26
+ });
27
+ it('should remove [tags]', function () {
28
+ var text = 'Here is a doc [doc_42] and some texte';
29
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe('Here is a doc and some texte');
30
+ });
31
+ it('should not remove simple REF or [REF]', function () {
32
+ var text = 'REF not closed [REF]not closed either';
33
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe(text);
34
+ });
35
+ it('should not remove lowercase ref', function () {
36
+ var text = 'before refdoc_1/ref after';
37
+ expect((0, _helpers.sanitizeChatContent)(text)).toBe(text);
38
+ });
39
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cozy-search",
3
3
  "description": "UI components about search bar and IA assistant",
4
- "version": "0.8.2",
4
+ "version": "0.8.3",
5
5
  "author": {
6
6
  "name": "Cozy Cloud",
7
7
  "url": "https://github.com/cozy"
@@ -87,5 +87,5 @@
87
87
  "lint": "cd .. && yarn eslint --ext js,jsx,ts packages/cozy-search"
88
88
  },
89
89
  "types": "dist/index.d.ts",
90
- "gitHead": "d92e0d197621f65fe6c5c68c57d15595177eec7b"
90
+ "gitHead": "6a1b303d4030cd56bac5ea34c6a7773a2b53d2e5"
91
91
  }