<commit_before>/**
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Detector for document.getElementById and document.getElementsByName
 * @bug: https://code.google.com/p/compatibility-detector/issues/detail?id=1
 * @bug: https://code.google.com/p/compatibility-detector/issues/detail?id=44
 * $bug: https://code.google.com/p/compatibility-detector/issues/detail?id=117
 *
 * Document.getElementById and document.getElementsByName is introduced in DOM
 * level 1. Document.getElementById(elementId) returns the Element whose ID is
 * given by elementId. If no such element exists, returns null.
 * Document.getElementsByName(elementName) returns the (possibly empty)
 * collection of elements whose name value is given by elementName. This method
 * is case sensitive.
 *
 * In IE6 IE7 IE8(Q), document.getElementById(elementId) is case insensitive,
 * document.getElementById('X') will get element whose value of id attribute is
 * 'x'. And for a part of elements, it's confused with ID and name attribute,
 * document.getElementById(elementName) will return element whose value of name
 * attribute is equal to elementName.
 *
 * In IE6 IE7 IE8, for a part of elements,
 * document.getElementsByName(elementName) is case insensitive,
 * document.getElementsByName('X') will get elements whose value of name
 * attribute is 'x'.
 *
 * First hook document.getElementById and document.getElementsByName, so that we
 * can catch the argument id or name. When calling these methods and gets no
 * result, then traverse DOM tree. If case insensitive argument id or name is
 * existing in document, report problem.
 */

addScriptToInject(function() {

chrome_comp.CompDetect.declareDetector(

'getelementbyid_and_getelementsbyname',

chrome_comp.CompDetect.NonScanDomBaseDetector,

function constructor(rootNode) {
  var that = this;
  var ids;
  var commonNames;
  var namesOfEmbed;
  var namesOfFrameAndParam;

  this.getElementById_ = function(result, originalArguments, callStack) {
    var arg0 = originalArguments[0];
    if (arg0 == undefined)
      return;
    var lowerCaseArg0 = arg0.toLowerCase();
    var lowerCaseIds = getIds();

    // Handle SD9002
    if (!result && lowerCaseIds.indexOf(lowerCaseArg0) >= 0) {
      addProblem('SD9002');
    }<commit_msg>Fix bug occured when passing non-String argument to document.getElementById method. code review: http://codereview.appspot.com/4074043<commit_after>/**
 * Copyright 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Detector for document.getElementById and document.getElementsByName
 * @bug: https://code.google.com/p/compatibility-detector/issues/detail?id=1
 * @bug: https://code.google.com/p/compatibility-detector/issues/detail?id=44
 * $bug: https://code.google.com/p/compatibility-detector/issues/detail?id=117
 *
 * Document.getElementById and document.getElementsByName is introduced in DOM
 * level 1. Document.getElementById(elementId) returns the Element whose ID is
 * given by elementId. If no such element exists, returns null.
 * Document.getElementsByName(elementName) returns the (possibly empty)
 * collection of elements whose name value is given by elementName. This method
 * is case sensitive.
 *
 * In IE6 IE7 IE8(Q), document.getElementById(elementId) is case insensitive,
 * document.getElementById('X') will get element whose value of id attribute is
 * 'x'. And for a part of elements, it's confused with ID and name attribute,
 * document.getElementById(elementName) will return element whose value of name
 * attribute is equal to elementName.
 *
 * In IE6 IE7 IE8, for a part of elements,
 * document.getElementsByName(elementName) is case insensitive,
 * document.getElementsByName('X') will get elements whose value of name
 * attribute is 'x'.
 *
 * First hook document.getElementById and document.getElementsByName, so that we
 * can catch the argument id or name. When calling these methods and gets no
 * result, then traverse DOM tree. If case insensitive argument id or name is
 * existing in document, report problem.
 */

addScriptToInject(function() {

chrome_comp.CompDetect.declareDetector(

'getelementbyid_and_getelementsbyname',

chrome_comp.CompDetect.NonScanDomBaseDetector,

function constructor(rootNode) {
  var that = this;
  var ids;
  var commonNames;
  var namesOfEmbed;
  var namesOfFrameAndParam;

  this.getElementById_ = function(result, originalArguments, callStack) {
    var arg0 = originalArguments[0];
    if (arg0 == undefined || typeof arg0 != 'string')
      return;
    var lowerCaseArg0 = arg0.toLowerCase();
    var lowerCaseIds = getIds();

    // Handle SD9002
    if (!result && lowerCaseIds.indexOf(lowerCaseArg0) >= 0) {
      addProblem('SD9002');
    }
{'fraction_non_alphanumeric': 0.08848945731075009, 'fraction_numerical': 0.013826477704804701, 'mean_word_length': 4.328729281767956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819093', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1559, 'n_words': 595}