浏览代码

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 年前
父节点
当前提交
e403a68665
共有 2 个文件被更改,包括 4 次插入3 次删除
  1. 1
    2
      modules/RTC/RTCUtils.js
  2. 3
    1
      modules/xmpp/SDPUtil.js

+ 1
- 2
modules/RTC/RTCUtils.js 查看文件

@@ -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 查看文件

@@ -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;

正在加载...
取消
保存