Bläddra i källkod

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 år sedan
förälder
incheckning
e403a68665
2 ändrade filer med 4 tillägg och 3 borttagningar
  1. 1
    2
      modules/RTC/RTCUtils.js
  2. 3
    1
      modules/xmpp/SDPUtil.js

+ 1
- 2
modules/RTC/RTCUtils.js Visa fil

588
                         return attachMediaStream(element, stream);
588
                         return attachMediaStream(element, stream);
589
                     };
589
                     };
590
                     self.getStreamID = function (stream) {
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
                     self.getVideoSrc = function (element) {
593
                     self.getVideoSrc = function (element) {
595
                         if (!element) {
594
                         if (!element) {

+ 3
- 1
modules/xmpp/SDPUtil.js Visa fil

4
 
4
 
5
 SDPUtil = {
5
 SDPUtil = {
6
     filter_special_chars: function (text) {
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
     iceparams: function (mediadesc, sessiondesc) {
11
     iceparams: function (mediadesc, sessiondesc) {
10
         var data = null;
12
         var data = null;

Laddar…
Avbryt
Spara