nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: apostrophecms/sanitize-html
Pull request #521 (2021-12-04 19:16:06)

Fix trailing text issue on transformTag 
Fixes issue #506

Fixes regression caused by https://github.com/apostrophecms/sanitize-html/pull/395 in which `addedText` was never reseted to false after the `ontext` function was called for that tag.

Solution: reset `addedText` boolean to false in the onclosetag function.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ba3de1..7ec3c55 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## UNRELEASED
+
+- Fixed trailing text bug on `transformTags` options that was reported on [issue #506](https://github.com/punkave/sanitize-html/issues/506). Thanks to [Alex Rantos](https://github.com/alex-rantos).
+
 ## 2.6.0 (2021-11-23)
 
 - Support for regular expressions in the `allowedClasses` option. Thanks to [Alex Rantos](https://github.com/alex-rantos).
diff --git a/index.js b/index.js
index ed87028..3f0ff55 100644
--- a/index.js
+++ b/index.js
@@ -582,6 +582,7 @@ function sanitizeHtml(html, options, _recursing) {
         result = tempResult + escapeHtml(result);
         tempResult = '';
       }
+      addedText = false;
     }
   }, options.parser);
   parser.write(html);


Test patch:
diff --git a/test/test.js b/test/test.js
index 9dddc7a..5b343c1 100644
--- a/test/test.js
+++ b/test/test.js
@@ -228,6 +228,19 @@ describe('sanitizeHtml', function() {
     }), '<a href="http://somelink">some good text</a>');
   });
 
+  it('should preserve trailing text when replacing the tagName and adding new text via transforming function', function () {
+    assert.equal(sanitizeHtml('<p>text before <br> text after</p>', {
+      transformTags: {
+        br: function (_tagName, _attribs) {
+          return {
+            tagName: 'span',
+            text: ' '
+          };
+        }
+      }
+    }), '<p>text before <span> </span> text after</p>');
+  });
+
   it('should add new text when not initially set and replace attributes when they are changed by transforming function', function () {
     assert.equal(sanitizeHtml('<a href="http://somelink"></a>', {
       transformTags: {
Repository: apostrophecms/sanitize-html
Pull request #594 (2022-12-13 14:41:06)

Fix behavour for numbers
Fixes https://github.com/apostrophecms/sanitize-html/issues/593

## Summary

*Summarize the changes briefly, including which issue/ticket this resolves. If it closes an existing Github issue, include "Closes #[issue number]"*

## What are the specific steps to test this change?

*For example:*
> 1. npm install
> 2. npm run test

## What kind of change does this PR introduce?
*(Check at least one)*

- [x] Bug fix
- [ ] New feature
- [ ] Refactor
- [ ] Documentation
- [ ] Build-related changes
- [ ] Other

## Make sure the PR fulfills these requirements:

- [x] It includes a) the existing issue ID being resolved, b) a convincing reason for adding this feature, or c) a clear description of the bug it resolves
- [x] The changelog is updated
- [-] Related documentation has been updated
- [x] Related tests have been updated

If adding a new feature without an already open issue, it's best to open a **feature request issue** first and wait for approval before working on it.

**Other information:**



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 923f43d..5c73de6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 2.8.1 (2022-12-*)
+
+- Fix sanitize of number values with `htmlparser2` `^8.0.0` version.
+
 ## 2.8.0 (2022-12-12)
 
 - Upgrades `htmlparser2` to new major version `^8.0.0`. Thanks to [Kedar Chandrayan](https://github.com/kedarchandrayan) for this contribution.
diff --git a/index.js b/index.js
index ed152ad..bc7d0d4 100644
--- a/index.js
+++ b/index.js
@@ -83,6 +83,9 @@ function sanitizeHtml(html, options, _recursing) {
   if (html == null) {
     return '';
   }
+  if (typeof html === 'number') {
+    html = html.toString();
+  }
 
   let result = '';
   // Used for hot swapping the result variable with an empty string in order to "capture" the text written to it.


Test patch:
diff --git a/test/test.js b/test/test.js
index df6769f..72e285f 100644
--- a/test/test.js
+++ b/test/test.js
@@ -13,6 +13,13 @@ describe('sanitizeHtml', function() {
       allowedAttributes: false
     }), 'before &lt;img src="test.png" /&gt; after');
   });
+  it('should handle numbers as strings', () => {
+    assert.equal(sanitizeHtml(5, {
+      allowedTags: [ 'b', 'em', 'i', 's', 'small', 'strong', 'sub', 'sup', 'time', 'u' ],
+      allowedAttributes: {},
+      disallowedTagsMode: 'recursiveEscape'
+    }), '5');
+  });
   it('should pass through simple, well-formed markup', function() {
     assert.equal(sanitizeHtml('<div><p>Hello <b>there</b></p></div>'), '<div><p>Hello <b>there</b></p></div>');
   });