Sfoglia il codice sorgente

Prevent TypeError

The function filter_special_chars does not have to throw a TypeError
when its argument text is null or undefined because (1) it can be argued
that neither of these two contains special characters and (2) it is much
more convenient to have the check in the function in question rather at
its multiple call sites.
master
Lyubomir Marinov 9 anni fa
parent
commit
e403a68665
2 ha cambiato i file con 4 aggiunte e 3 eliminazioni
  1. 1
    2
      modules/RTC/RTCUtils.js
  2. 3
    1
      modules/xmpp/SDPUtil.js

+ 1
- 2
modules/RTC/RTCUtils.js Vedi File

@@ -588,8 +588,7 @@ var RTCUtils = {
588 588
                         return attachMediaStream(element, stream);
589 589
                     };
590 590
                     self.getStreamID = function (stream) {
591
-                        var id = SDPUtil.filter_special_chars(stream.label);
592
-                        return id;
591
+                        return SDPUtil.filter_special_chars(stream.label);
593 592
                     };
594 593
                     self.getVideoSrc = function (element) {
595 594
                         if (!element) {

+ 3
- 1
modules/xmpp/SDPUtil.js Vedi File

@@ -4,7 +4,9 @@ var RTCBrowserType = require("../RTC/RTCBrowserType");
4 4
 
5 5
 SDPUtil = {
6 6
     filter_special_chars: function (text) {
7
-        return text.replace(/[\\\/\{,\}\+]/g, "");
7
+        // XXX Neither one of the falsy values (e.g. null, undefined, false,
8
+        // "", etc.) "contain" special chars.
9
+        return text ? text.replace(/[\\\/\{,\}\+]/g, "") : text;
8 10
     },
9 11
     iceparams: function (mediadesc, sessiondesc) {
10 12
         var data = null;

Loading…
Annulla
Salva