{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/9801","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/9801/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/9801/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/9801/events","html_url":"https://github.com/nodejs/node/issues/9801","id":191777342,"number":9801,"title":"byteOffset argument in buffer indexOf / lastIndexOf has some contradictions in code vs doc vs test","user":{"login":"vsemozhetbyt","id":10393198,"avatar_url":"https://avatars.githubusercontent.com/u/10393198?v=3","gravatar_id":"","url":"https://api.github.com/users/vsemozhetbyt","html_url":"https://github.com/vsemozhetbyt","followers_url":"https://api.github.com/users/vsemozhetbyt/followers","following_url":"https://api.github.com/users/vsemozhetbyt/following{/other_user}","gists_url":"https://api.github.com/users/vsemozhetbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/vsemozhetbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsemozhetbyt/subscriptions","organizations_url":"https://api.github.com/users/vsemozhetbyt/orgs","repos_url":"https://api.github.com/users/vsemozhetbyt/repos","events_url":"https://api.github.com/users/vsemozhetbyt/events{/privacy}","received_events_url":"https://api.github.com/users/vsemozhetbyt/received_events","type":"User","site_admin":false},"labels":[{"id":155267414,"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-11-26T00:15:08Z","updated_at":"2016-12-09T22:12:29Z","closed_at":null,"body":"* **Version**: 7.2.0\r\n* **Platform**: Windows 7\r\n* **Subsystem**: buffer\r\n\r\nSome contradictions in status quo:\r\n\r\n1. `buffer.lastIndexOf()` [code example in doc](https://nodejs.org/api/buffer.html#buffer_buf_lastindexof_value_byteoffset_encoding):\r\n```js\r\nconst utf16Buffer = Buffer.from('\\u039a\\u0391\\u03a3\\u03a3\\u0395', 'ucs2');\r\n\r\n// Prints: 6\r\nconsole.log(utf16Buffer.lastIndexOf('\\u03a3', null, 'ucs2'));\r\n```\r\nActually, it prints `-1` now.\r\n\r\n2. `buffer.js` [coerces](https://github.com/nodejs/node/blob/master/lib/buffer.js#L601) `byteOffset` `null` to `0`.  However, in the next block it [checks](https://github.com/nodejs/node/blob/master/lib/buffer.js#L603) if `byteOffset` is `null` to make it default `byteOffset` if so.\r\n\r\n3. `test-buffer-indexof.js` [expects](https://github.com/nodejs/node/blob/master/test/parallel/test-buffer-indexof.js#L407) `null` `byteOffset` to return `-1`, i.e. it expects `null` `byteOffset` not to be converted into the default `byteOffset`.\r\n\r\nMaybe the fix steps could be these:\r\n\r\n1. `buffer.js` should not coerce `null` to `Number`.\r\n2.  `test-buffer-indexof.js` should expect `null` `byteOffset` to be converted into the default `byteOffset`.\r\n3. Doc should clarify which argument types and values trigger default. Maybe something like `position` remarks in the `fs` doc for [`fs.read()`](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) and [`fs.write()`](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback)."},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/266137516","html_url":"https://github.com/nodejs/node/issues/9801#issuecomment-266137516","issue_url":"https://api.github.com/repos/nodejs/node/issues/9801","id":266137516,"user":{"login":"vsemozhetbyt","id":10393198,"avatar_url":"https://avatars.githubusercontent.com/u/10393198?v=3","gravatar_id":"","url":"https://api.github.com/users/vsemozhetbyt","html_url":"https://github.com/vsemozhetbyt","followers_url":"https://api.github.com/users/vsemozhetbyt/followers","following_url":"https://api.github.com/users/vsemozhetbyt/following{/other_user}","gists_url":"https://api.github.com/users/vsemozhetbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/vsemozhetbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsemozhetbyt/subscriptions","organizations_url":"https://api.github.com/users/vsemozhetbyt/orgs","repos_url":"https://api.github.com/users/vsemozhetbyt/repos","events_url":"https://api.github.com/users/vsemozhetbyt/events{/privacy}","received_events_url":"https://api.github.com/users/vsemozhetbyt/received_events","type":"User","site_admin":false},"created_at":"2016-12-09T22:12:29Z","updated_at":"2016-12-09T22:12:29Z","body":"@trevnorris  If I get it right, it seems the comment [has been changed already](https://github.com/nodejs/node/pull/10162/files#diff-196d056a936b6d2649721eb639e0442bR593). "}}
{"actor":{"display_login":"vsemozhetbyt"}}