11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst ArrayStream = require('../common/arraystream');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cicommon.skipIfDumbTerminal();
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst readline = require('readline');
91cb0ef41Sopenharmony_ciconst rli = new readline.Interface({
101cb0ef41Sopenharmony_ci  terminal: true,
111cb0ef41Sopenharmony_ci  input: new ArrayStream(),
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cilet recursionDepth = 0;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// Minimal reproduction for #46731
171cb0ef41Sopenharmony_ciconst testInput = ' \n}\n';
181cb0ef41Sopenharmony_ciconst numberOfExpectedLines = testInput.match(/\n/g).length;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cirli.on('line', () => {
211cb0ef41Sopenharmony_ci  // Abort in case of infinite loop
221cb0ef41Sopenharmony_ci  if (recursionDepth > numberOfExpectedLines) {
231cb0ef41Sopenharmony_ci    return;
241cb0ef41Sopenharmony_ci  }
251cb0ef41Sopenharmony_ci  recursionDepth++;
261cb0ef41Sopenharmony_ci  // Write something recursively to readline
271cb0ef41Sopenharmony_ci  rli.write('foo');
281cb0ef41Sopenharmony_ci});
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_cirli.write(testInput);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciassert.strictEqual(recursionDepth, numberOfExpectedLines);
34