summaryrefslogtreecommitdiff
path: root/test/ruby/test_file.rb
AgeCommit message (Collapse)Author
2024-01-10Fix CRLF -> LF conversion on read for rb_io_fdopen & rb_file_openKJ Tsanaktsidis
When opening a file with `File.open`, and then setting the encoding with `IO#set_encoding`, it still correctly performs CRLF -> LF conversion on Windows when reading files with a CRLF line ending in them (in text mode). However, the file is opened instead with either the `rb_io_fdopen` or `rb_file_open` APIs from C, the CRLF conversion is _NOT_ set up correctly; it works if the encoding is not specified, but if `IO#set_encoding` is called, the conversion stops happening. This seems to be because the encflags never get ECONV_DEFAULT_NEWLINE_DECORATOR set in these codepaths. Concretely, this means that the conversion doesn't happen in the following circumstances: * When loading ruby files with require (that calls rb_io_fdopen) * When parsing ruuby files with RubyVM::AbstractSyntaxTree (that calls rb_file_open). This then causes the ErrorHighlight tests to fail on windows if git has checked them out with CRLF line endings - the error messages it's testing wind up with literal \r\n sequences in them because the iseq text from the parser contains un-newline-converted strings. This commit fixes the problem by copy-pasting the relevant snippet which sets this up in `rb_io_extract_modeenc` (for the File.open path) into the relevant codepaths for `rb_io_fdopen` and `rb_file_open`. [Bug #20101]
2022-12-08Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-08-19Support Encoding::Converter newline: :lf and :lf_newline optionsJeremy Evans
Previously, newline: :lf was accepted but ignored. Where it should have been used was commented out code that didn't work, but unlike all other invalid values, using newline: :lf did not raise an error. This adds support for newline: :lf and :lf_newline, for consistency with newline: :cr and :cr_newline. This is basically the same as universal_newline, except that it only affects writing and not reading due to RUBY_ECONV_NEWLINE_DECORATOR_WRITE_MASK. Add tests for the File.open :newline option while here. Fixes [Bug #12436] Notes: Merged: https://github.com/ruby/ruby/pull/4590
2022-01-04Use omit instead of skip: test/ruby/**/*.rbHiroshi SHIBATA
2019-12-18Use a temporary file for chown testNobuyoshi Nakada
Errno::EROFS may occur when the source tree is placed in a read-only filesystem.
2019-12-12[cygwin] fix File.absolute_path? testNobuyoshi Nakada
Paths start with the root are absolute on cygwin, regardless the drive letter.
2019-12-12Cygwin path cannot be mapped to a UNC as-isNobuyoshi Nakada
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-12Added assertions for realpath and realdirpathNobuyoshi Nakada
It is said that realpath(3) and realdirpath(3) on some platforms may return a relative path.
2019-09-05Add tests for `File.absolute_path?`David Rodríguez
[Feature #15868]
2019-08-30Fix keyword argument separation warnings in testJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-13UTF LE is fixed at least the first 2 bytesNobuyoshi Nakada
* io.c (io_strip_bom): if the first 2 bytes are 0xFF0xFE, it should be a little-endian UTF, 16 or 32. [Bug #16099]
2019-04-28Always mark the string returned by File.realpath as taintedJeremy Evans
This string can include elements that were not in either string passed to File.realpath, even if one of the strings is an absolute path, due to symlinks: ```ruby Dir.mkdir('b') unless File.directory?('b') File.write('b/a', '') unless File.file?('b/a') File.symlink('b', 'c') unless File.symlink?('c') path = File.realpath('c/a'.untaint, Dir.pwd.untaint) path # "/home/testr/ruby/b/a" path.tainted? # should be true, as 'b' comes from file system ``` [Bug #15803]
2018-12-11CentOS-7 (1810)'s header has O_TMPFILE but kernel doesn't support itnaruse
http://rubyci.s3.amazonaws.com/centos7/ruby-trunk/log/20181206T080003Z.diff.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-28file.c: realpath on special symlinknobu
* file.c (realpath_rec): fallback to symlink path when it is accessible but the link target is not actual entry on file systems. [ruby-dev:50487] [Bug #14557] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28`$SAFE` as a process global state. [Feature #14250]ko1
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state. * vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc` objects don't need to keep `$SAFE` at the creation. Also make `is_from_method` and `is_lambda` as 1 bit fields. * cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation. * eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access `vm->safe_level_` directly. * eval_jump.c: End procs `END{}` doesn't keep `$SAFE`. * proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c. * safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes. * safe.c (safe_setter): use `rb_set_safe_level()`. * thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`. It should be obsolete. * transcode.c (load_transcoder_entry): `rb_safe_level()` only returns 0 or 1 so that this check is not needed. * vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc. * vm.c (rb_proc_create): renamed to `proc_create`. * vm.c (rb_proc_dup): moved from proc.c. * vm.c (vm_invoke_proc): do not need to set and restore `$SAFE` for `Proc#call`. * vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer meaning. * lib/drb/drb.rb: restore `$SAFE`. * lib/erb.rb: restore `$SAFE`, too. * test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests. * test/rubygems/test_gem.rb: do not set `$SAFE = 1`. * bootstraptest/test_proc.rb: catch up this change. * spec/ruby/optional/capi/string_spec.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: ditto. * test/fiddle/test_func.rb: ditto. * test/fiddle/test_handle.rb: ditto. * test/net/imap/test_imap_response_parser.rb: ditto. * test/pathname/test_pathname.rb: ditto. * test/readline/test_readline.rb: ditto. * test/ruby/test_file.rb: ditto. * test/ruby/test_optimization.rb: ditto. * test/ruby/test_proc.rb: ditto. * test/ruby/test_require.rb: ditto. * test/ruby/test_thread.rb: ditto. * test/rubygems/test_gem_specification.rb: ditto. * test/test_tempfile.rb: ditto. * test/test_tmpdir.rb: ditto. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-18check EOPNOTSUPP.ko1
* test/ruby/test_file.rb (test_open_tempfile_path): skip EOPNOTSUPP (observed on Ubuntu 16 on Docker). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01file.c: infect from argumentsnobu
* file.c (rb_check_realpath_internal): infetct the result with arguments, no taint if none are tainted and cwd is not used. [ruby-core:83583] [Bug #14060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01revert r60596 because it cause faulure on TestFile#test_realpath_taintednessko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01file.c: infect from argumentsnobu
* file.c (rb_check_realpath_internal): infetct the result with arguments, no taint if none are tainted and cwd is not used. [ruby-core:83583] [Bug #14060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-08Remove unnecessary `require 'thread'`kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31Skip test_open_tempfile_path on EINVALsorah
Looks like File::Constants::TMPFILE could be defined even when not supported on system. Just skip the test when we get EINVAL on open(2). * test/ruby/test_file.rb(test_open_tempfile_path): Skip when EINVAL occured on File.open. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31File#path: Raise IOError when a file is O_TMPFILEsorah
File#path for a file opened with O_TMPFILE has no meaning. A filepath returned by this method isn't guarranteed about its accuracy, but files opened with O_TMPFILE are known its recorded path has no meaning. So let them not to return any pathname. After a discussion in ruby-core, just returning Qnil makes guessing the root cause difficult. Instead, this patch makes the method to raise an error. Other consideration is calling fnctl(2) on rb_file_path, but it adds a overhead, and it's difficult to determine O_TMPFILE status after fd has been closed. [Feature #13568] * io.c(rb_file_open_generic): Set Qnil to fptr->pathv when opening a file using O_TMPFILE * file.c(rb_file_path): Raise IOError when fptr->pathv is Qnil * file.c(rb_file_path): [DOC] Update for the new behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06EPERM by symlinknobu
* test/ruby/test_file.rb (test_realpath_encoding): EPERM can raise on cygwin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05Refix r56559 with Fs.noatime? [ruby-core:77943] [Bug #12903]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56585 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05test_file.rb: fix noatimenobu
* test/ruby/test_file.rb (TestFile#test_stat): fix noatime case. [ruby-core:77943] [Bug #12903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-30Use qualified namesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-27* test/ruby/test_file.rb (TestFile#test_realpath_encoding): rescue Errno::EACCESusa
and skip the testcase because it'll be raised on Windows always unless the runner doesn't have the administrator privilege. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16Add frozen_string_literal: false for all filesnaruse
When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-28test_file.rb: fix name clashnobu
* test/ruby/test_file.rb (test_realpath_encoding): get rid of name clash on case-insensitive filesystem in ascii only environment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-08fix a typo of test method name.nagachika
* test/ruby/test_file.rb (test_realdirpath_junction): fix a typo of method name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-08* test/ruby/test_file.rb (TestFile#test_realdirpath_junktion): test for r51790.usa
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-09-02file.c: use filesystem encodingnobu
* file.c (rb_realpath_internal): use filesystem encoding if the argument is in ASCII encodings. * win32/file.c (rb_readlink): needs the result encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-17* include/ruby/ruby.h: $SAFE=3 is now obsolete.hsbt
* ext/socket/init.c, ext/socket/socket.c, ext/socket/tcpsocket.c ext/socket/udpsocket.c, gc.c, object.c, re.c, safe.c: removed code for $SAFE=3 * bootstraptest/test_method.rb, test/erb/test_erb.rb, test/ruby/test_dir.rb test/ruby/test_file.rb, test/ruby/test_method.rb, test/ruby/test_regexp.rb test/ruby/test_thread.rb: remove tests for $SAFE=3 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-13* file.c (rb_stat_ino): get inode from the interval of struct st.naruse
* win32/win32.c (stati64_set_inode): get nFilIndexHigh/Low, and set it to the interval of struct st as inode. * win32/win32.c (stati64_set_inode_handle): call stati64_set_inode. * win32/win32.c (rb_w32_fstati64): call stati64_set_inode_handle. * win32/win32.c (stati64_handle): call stati64_set_inode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-12* file.c (File::SHARE_DELETE): new flag to be able to delete opened fileusa
on Windows. * include/win32/win32.c (O_SHARE_DELETE): new pseudo file mode flag. * win32/win32.c (rb_w32_{w,}open): support above flag. [EXPERIMENTAL] * NEWS: mention about this feature. [Feature #11218] [ruby-dev:49022] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-20test_file.rb: just skip assertionnobu
* test/ruby/test_file.rb (TestFile#test_stat): skip an assertion only, not making the entire test skipped git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-25safe.c: preserve encodingnobu
* safe.c (rb_insecure_operation): preserve encoding of the called method name in error messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-13* test/lib/envutil.rb: Moved from test/ruby/.akr
* test/lib/find_executable.rb: Ditto. * test/lib/memory_status.rb: Ditto. * test/lib/test/unit.rb: require envutil. * test/: Don't require envutil in test files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-31Join threads.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-26Use Tempfile.create instead of Tempfile.new.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-26* test/ruby/test_file.rb: skip the test of atime on Windows, becauseusa
Windows delays updating atime about 1 hour. see more details: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290%28v=vs.85%29.aspx git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-25Remove tempfiles.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-23test_file.rb: fix ctime on Windowsnobu
* test/ruby/test_file.rb (test_stat): `ctime` on Windows is not last changed time. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-23test_file.rb: estimate birthtimenobu
* test/ruby/test_file.rb (test_stat): estimate expected birthtime by pinching. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-22* file.c (stat_birthtime): add birthtime support [Feature #9647]naruse
* file.c (rb_stat_birthtime): add File::Stat.birthtime * file.c (rb_file_s_birthtime): add File.birthtime * file.c (rb_file_birthtime): add File#birthtime * configure.in: check struct stat.st_birthtimespec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-22revert File::Statfs [Feature #9772]naruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-28* configure.in: check struct statvfs and struct statvfs.f_fstypename.naruse
* configure.in: on NetBSD fstatfs is obsoleted. * file.c: support NetBSD for File::Statfs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-04-24suppress warnings: ambiguous first argument; put parentheses or even spacesnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e