Skip to content

Commit

Permalink
Remove stringUtils. Bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Jan 22, 2016
1 parent b215562 commit cd289ee
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testcafe-hammerhead",
"description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).",
"version": "4.1.3",
"version": "5.0.0",
"homepage": "https://github.com/DevExpress/testcafe-hammerhead",
"bugs": "https://github.com/DevExpress/testcafe-hammerhead/issues",
"license": "https://github.com/DevExpress/testcafe-hammerhead/blob/master/LICENSE",
Expand Down
4 changes: 2 additions & 2 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as eventUtils from './utils/event';
import * as typeUtils from './utils/types';
import * as positionUtils from './utils/position';
import * as styleUtils from './utils/style';
import * as stringUtils from '../utils/string';
import trim from '../utils/string-trim';
import { getProxyUrl } from './utils/url';
import isJQueryObj from './utils/is-jquery-object';
import extend from './utils/extend';
Expand Down Expand Up @@ -72,7 +72,7 @@ class Hammerhead {
position: positionUtils,
style: styleUtils,
types: typeUtils,
string: stringUtils,
trim: trim,
isJQueryObj: isJQueryObj,
extend: extend
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/sandbox/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as destLocation from '../utils/destination-location';
import * as cookieUtils from '../utils/cookie';
import { isCrossDomainWindows } from '../utils/dom';
import { queuedAsyncServiceMsg } from '../transport';
import { trim } from '../../utils/string';
import trim from '../../utils/string-trim';

export default class CookieSandbox extends SandboxBase {
_getSettings () {
Expand Down
2 changes: 1 addition & 1 deletion src/client/utils/cookie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trim } from '../../utils/string';
import trim from '../../utils/string-trim';

// NOTE: The name/key cannot be empty, but the value can.
const COOKIE_PAIR_REGEX = /^([^=;]+)\s*=\s*(("?)[^\n\r\0]*\3)/;
Expand Down
2 changes: 1 addition & 1 deletion src/client/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import nativeMethods from '../sandbox/native-methods';
import * as urlUtils from './url';
import { sameOriginCheck } from './destination-location';
import { isFirefox, isWebKit, isIE, isOpera } from './browser';
import { trim } from '../../utils/string';
import trim from '../../utils/string-trim';

// NOTE: We should avoid using native object prototype methods,
// since they can be overriden by the client code. (GH-245)
Expand Down
3 changes: 1 addition & 2 deletions src/processing/resources/manifest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import ResourceProcessorBase from './resource-processor-base';
import { trim } from '../../utils/string';

class ManifestProcessor extends ResourceProcessorBase {
processResource (manifest, ctx, charset, urlReplacer) {
var lines = manifest.split('\n');

for (var i = 0; i < lines.length; i++) {
var line = trim(lines[i]);
var line = lines[i].trim();

if (line && line !== 'CACHE MANIFEST' && line !== 'NETWORK:' && line !== 'FALLBACK:' &&
line !== 'CACHE:' && line[0] !== '#' && line !== '*') {
Expand Down
9 changes: 4 additions & 5 deletions src/processing/script/instrumented.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,21 @@ export const PROPERTIES = [
const INSTRUMENTED_METHOD_RE = new RegExp(`^(${METHODS.join('|')})$`);
const INSTRUMENTED_PROPERTY_RE = new RegExp(`^(${PROPERTIES.join('|')})$`);

// NOTE: The obfuscated version of the mootools framework contains code
// that removes the RegExp.prototype.test method and restores it later.
// NOTE: Mootools framework contains code that removes the RegExp.prototype.test
// method and restores it later.
// delete z[A]; // z = RegExp.prototype, A = "test"
// __set$(z, A, x.protect()); // x.protect - returns the removed method
// The __set$ function calls the test method of the regular expression. (GH-331)
var reTest = RegExp.prototype.test;
var test = (regexp, str) => regexp.test ? regexp.test(str) : reTest.call(regexp, str);

// NOTE: we can't use the map approach here, because
// cases like `WRAPPABLE_METHOD['toString']` will fail.
// We could use the hasOwnProperty test, but it is
// significantly slower than the regular expression test
export function shouldInstrumentMethod (name) {
return INSTRUMENTED_METHOD_RE.test(name);
return reTest.call(INSTRUMENTED_METHOD_RE, name);
}

export function shouldInstrumentProperty (name) {
return test(INSTRUMENTED_PROPERTY_RE, name);
return reTest.call(INSTRUMENTED_PROPERTY_RE, name);
}
8 changes: 3 additions & 5 deletions src/utils/string.js → src/utils/string-trim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
// in our scripts, we expect it to have the default behavior. Therefore, in order to protect
// ourselves from spoofing, we must use our own implementation.

export function trim (str) {
return str.replace(/^\s+|\s+$/g, '');
}
var strTrim = String.prototype.trim;

export function endsWith (str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
export default function (str) {
return strTrim.call(str);
}
6 changes: 3 additions & 3 deletions src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Do not use any browser or node-specific API!
// -------------------------------------------------------------

import * as stringUtils from './string';
import trim from './string-trim';

//Const
const PROTOCOL_RE = /(^(\w+?\:))/;
Expand Down Expand Up @@ -146,7 +146,7 @@ export function parseUrl (url) {
if (!url)
return parsed;

url = stringUtils.trim(url);
url = trim(url);

// Protocol
var hasImplicitProtocol = false;
Expand Down Expand Up @@ -243,7 +243,7 @@ export function prepareUrl (url) {
}

export function ensureTrailingSlash (srcUrl, processedUrl) {
var hasTrailingSlash = stringUtils.endsWith(srcUrl, '/');
var hasTrailingSlash = /\/$/.test(srcUrl);

if (!hasTrailingSlash)
processedUrl = processedUrl.replace(/\/$/, '');
Expand Down

0 comments on commit cd289ee

Please sign in to comment.