Repository: axios/axios (js)

Issue:
'clear' tests are not really testing anything
### Describe the bug

The following test code in `AxiosHeaders.js`

```
  describe('clear', ()=> {
    it('should clear all headers', () => {
      const headers = new AxiosHeaders({x: 1, y:2});

      headers.clear();

      assert.notDeepStrictEqual(headers, {});
    });

    it('should clear matching headers if a matcher was specified', () => {
      const headers = new AxiosHeaders({foo: 1, 'x-foo': 2, bar: 3});

      assert.notDeepStrictEqual(headers, {foo: 1, 'x-foo': 2, bar: 3});

      headers.clear(/^x-/);

      assert.notDeepStrictEqual(headers, {foo: 1, bar: 3});
    });
  });
```

Doesn't fail if you remove the implementation for `headers.clear()`

### To Reproduce

Remove the following lines

```
  clear(matcher) {
    const keys = Object.keys(this);
    let i = keys.length;
    let deleted = false;

    while (i--) {
      const key = keys[i];
      if(!matcher || matchHeaderValue(this, this[key], key, matcher)) {
        delete this[key];
        deleted = true;
      }
    }

    return deleted;
  }
```

to 

```
  clear(matcher) {
    return true;
  }
```

### Code snippet

_No response_

### Expected behavior

Tests should fail

### Axios Version

_No response_

### Adapter Version

_No response_

### Browser

_No response_

### Browser Version

_No response_

### Node.js Version

_No response_

### OS

_No response_

### Additional Library Versions

_No response_

### Additional context/Screenshots

_No response_

Pull request:
fix(headers): fixed the filtering logic of the clear method;
Closes #5539;

Patch:
diff --git a/lib/core/AxiosHeaders.js b/lib/core/AxiosHeaders.js
index 1cf84b9..138384c 100644
--- a/lib/core/AxiosHeaders.js
+++ b/lib/core/AxiosHeaders.js
@@ -33,11 +33,15 @@ function isValidHeaderName(str) {
   return /^[-_a-zA-Z]+$/.test(str.trim());
 }
 
-function matchHeaderValue(context, value, header, filter) {
+function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
   if (utils.isFunction(filter)) {
     return filter.call(this, value, header);
   }
 
+  if (isHeaderNameFilter) {
+    value = header;
+  }
+
   if (!utils.isString(value)) return;
 
   if (utils.isString(filter)) {
@@ -181,7 +185,7 @@ class AxiosHeaders {
 
     while (i--) {
       const key = keys[i];
-      if(!matcher || matchHeaderValue(this, this[key], key, matcher)) {
+      if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
         delete this[key];
         deleted = true;
       }


Test patch:
diff --git a/test/unit/core/AxiosHeaders.js b/test/unit/core/AxiosHeaders.js
index e52efb7..23f824e 100644
--- a/test/unit/core/AxiosHeaders.js
+++ b/test/unit/core/AxiosHeaders.js
@@ -242,17 +242,17 @@ describe('AxiosHeaders', function () {
 
       headers.clear();
 
-      assert.notDeepStrictEqual(headers, {});
+      assert.deepStrictEqual({...headers.toJSON()}, {});
     });
 
     it('should clear matching headers if a matcher was specified', () => {
       const headers = new AxiosHeaders({foo: 1, 'x-foo': 2, bar: 3});
 
-      assert.notDeepStrictEqual(headers, {foo: 1, 'x-foo': 2, bar: 3});
+      assert.deepStrictEqual({...headers.toJSON()}, {foo: '1', 'x-foo': '2', bar: '3'});
 
       headers.clear(/^x-/);
 
-      assert.notDeepStrictEqual(headers, {foo: 1, bar: 3});
+      assert.deepStrictEqual({...headers.toJSON()}, {foo: '1', bar: '3'});
     });
   });