Skip to content

Commit

Permalink
refactor: Replaced instances of substr() with substring() (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 authored Jun 13, 2024
1 parent 07a841b commit 8f96c73
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ API.prototype.getBrowserTimingHeader = function getBrowserTimingHeader(options =
* Only the first 13 chars of the license should be used for hashing with
* the transaction name.
*/
const key = config.license_key.substr(0, 13)
const key = config.license_key.substring(0, 13)
rumHash.transactionName = hashes.obfuscateNameUsingKey(name, key)

rumHash.queueTime = trans.queueTime
Expand Down
4 changes: 2 additions & 2 deletions bin/create-docs-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function formatReleaseNotes(releaseDate, version, body, frontmatter) {
'---',
'subject: Node.js agent',
`releaseDate: '${releaseDate}'`,
`version: ${version.substr(1)}`, // remove the `v` from start of version
`version: ${version.substring(1)}`, // remove the `v` from start of version
`downloadLink: 'https://www.npmjs.com/package/newrelic'`,
`security: ${frontmatter.security}`,
`bugs: ${frontmatter.bugfixes}`,
Expand Down Expand Up @@ -279,7 +279,7 @@ function addReleaseNotesFile(body, version) {

function getFileName(version) {
// change `v0.0.0` to `0-0-0`
version = version.substr(1).replace(/\./g, '-')
version = version.substring(1).replace(/\./g, '-')
const FILE = `node-agent-${version}.mdx`
return `${RELEASE_NOTES_PATH}/${FILE}`
}
Expand Down
2 changes: 1 addition & 1 deletion lib/config/attribute-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ function _convertRulesToRegex(rules) {
if (i !== r.length - 1) {
v += '.'
} else if (/\\\*$/.test(v)) {
v = v.substr(0, v.length - 2)
v = v.substring(0, v.length - 2)
}

const idx = c.findIndex(function findV(a) {
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/aws-sdk/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function grabLastUrlSegment(url = '/') {
// string for null, undefined, NaN etc.
url = '' + (url || '/')
const lastSlashIndex = url.lastIndexOf('/')
return url.substr(lastSlashIndex + 1)
return url.substring(lastSlashIndex + 1)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/shim/datastore-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ function parseQuery(query, nodule) {
// strip enclosing special characters from collection (table) name
if (typeof collection === 'string' && collection.length > 2) {
if (/^[\[{'"`]/.test(collection)) {
collection = collection.substr(1)
collection = collection.substring(1)
}
if (/[\]}'"`]$/.test(collection)) {
collection = collection.substr(0, collection.length - 1)
collection = collection.substring(0, collection.length - 1)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/transaction/name-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ NameState.prototype.getPath = function getPath() {
if (a[0] !== '/' && path[path.length - 1] !== '/') {
path += '/'
} else if (a[0] === '/' && path[path.length - 1] === '/') {
a = a.substr(1)
a = a.substring(1)
}
path += a
}
Expand Down
5 changes: 3 additions & 2 deletions lib/util/hashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function calculatePathHash(appName, pathName, referingPathHash) {
const result = (rotated ^ hash) >>> 0

// This is a trick to pad it out to 8 chars regardless of length.
return ('00000000' + result.toString(16)).substr(-8)
const str = '00000000' + result.toString(16)
return str.substring(str.length - 8)
}

function getHash(appName, txName) {
Expand Down Expand Up @@ -78,7 +79,7 @@ function int32ToByteArray(int32) {
// Lookup table for converting byte values to hex
const byteToHex = []
for (let i = 0; i < 256; ++i) {
byteToHex[i] = (i + 0x100).toString(16).substr(1)
byteToHex[i] = (i + 0x100).toString(16).substring(1)
}

function makeId(length = 16) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utilization/docker-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports.getBootId = function getBootId(agent, callback) {
if (data.length !== 36) {
bootIdError()
if (data.length > 128) {
data = data.substr(0, 128)
data = data.substring(0, 128)
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/utilization/gcp-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ function fetchGCPInfo(agent, callback) {
agent.metrics.getOrCreateMetric(NAMES.UTILIZATION.GCP_ERROR).incrementCallCount()
} else {
// normalize
results.machineType = results.machineType.substr(results.machineType.lastIndexOf('/') + 1)
results.zone = results.zone.substr(results.zone.lastIndexOf('/') + 1)
results.machineType = results.machineType.substring(
results.machineType.lastIndexOf('/') + 1
)
results.zone = results.zone.substring(results.zone.lastIndexOf('/') + 1)

resultDict = results
}
Expand Down
16 changes: 8 additions & 8 deletions test/integration/instrumentation/http-rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ test('custom naming rules should be applied early for RUM', function (t) {
function done(res) {
res.pipe(
new StreamSink(function (err, header) {
t.equal(header.substr(0, 7), '<script', 'should generate RUM headers')
t.equal(header.substring(0, 7), '<script', 'should generate RUM headers')
header.split(';').forEach(function (element) {
if (element.substr(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substr(DATA_PREFIX.length, element.length)
if (element.substring(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substring(DATA_PREFIX.length, element.length)
const data = JSON.parse(dataString)
const tx = hashes.deobfuscateNameUsingKey(
data.transactionName,
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(tx, 'WebTransaction/NormalizedUri/WORKING', 'should normalize url before RUM')
}
Expand Down Expand Up @@ -106,14 +106,14 @@ test('custom web transactions should have rules applied for RUM', function (t) {

api.startWebTransaction('/test', function () {
const header = api.getBrowserTimingHeader()
t.equal(header.substr(0, 7), '<script', 'should generate RUM headers')
t.equal(header.substring(0, 7), '<script', 'should generate RUM headers')
header.split(';').forEach(function (element) {
if (element.substr(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substr(DATA_PREFIX.length, element.length)
if (element.substring(0, DATA_PREFIX.length) === DATA_PREFIX) {
const dataString = element.substring(DATA_PREFIX.length, element.length)
const data = JSON.parse(dataString)
const tx = hashes.deobfuscateNameUsingKey(
data.transactionName,
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(tx, 'WebTransaction/NormalizedUri/WORKING', 'url normalized before RUM')
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/rum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ tap.test('the RUM API', function (t) {
t.ok(payload)
const deobf = hashes.deobfuscateNameUsingKey(
payload[1],
agent.config.license_key.substr(0, 13)
agent.config.license_key.substring(0, 13)
)
t.equal(JSON.parse(deobf).u.hello, 1)
t.end()
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/express/render.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function runTests(conf) {

app.get(TEST_PATH, function (req, res) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.render('index', { title: 'yo dawg', rum: rum })
})

Expand Down
2 changes: 1 addition & 1 deletion test/versioned/hapi/render.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ tap.test('agent instrumentation of Hapi', function (t) {
path: '/test',
handler: function (req, h) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
return h.view('index', { title: 'yo dawg', rum: rum })
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/restify/pre-7/rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tap.test('Restify router introspection', function (t) {

server.get('/test/:id', function (req, res, next) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.send({ status: 'ok' })
next()
})
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/restify/rum.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tap.test('Restify router introspection', function (t) {

server.get('/test/:id', function (req, res, next) {
const rum = api.getBrowserTimingHeader()
t.equal(rum.substr(0, 7), '<script')
t.equal(rum.substring(0, 7), '<script')
res.send({ status: 'ok' })
next()
})
Expand Down

0 comments on commit 8f96c73

Please sign in to comment.