Explorar el Código

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.
tags/v0.0.2
Lyubomir Marinov hace 9 años
padre
commit
e403a68665
Se han modificado 2 ficheros con 4 adiciones y 3 borrados
  1. 1
    2
      modules/RTC/RTCUtils.js
  2. 3
    1
      modules/xmpp/SDPUtil.js

+ 1
- 2
modules/RTC/RTCUtils.js Ver fichero

@@ -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 Ver fichero

@@ -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…
Cancelar
Guardar