Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Properly escape double quotes in shell commands on Windows#552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jcouball merged 2 commits intomasterfromwindows_escape
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletionslib/git/lib.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1191,8 +1191,9 @@ def escape_for_sh(s)
end

def escape_for_windows(s)
# Windows does not need single quote escaping inside double quotes
%Q{"#{s}"}
# Escape existing double quotes in s and then wrap the result with double quotes
escaped_string = s.to_s.gsub('"','\\"')
%Q{"#{escaped_string}"}
end

def windows_platform?
Expand Down
22 changes: 22 additions & 0 deletionstests/units/test_windows_cmd_escaping.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
# encoding: utf-8

require File.dirname(__FILE__) + '/../test_helper'

# Test diff when the file path has to be quoted according to core.quotePath
# See https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
#
class TestWindowsCmdEscaping < Test::Unit::TestCase
def test_commit_with_double_quote_in_commit_message
expected_commit_message = 'Commit message with "double quotes"'
in_temp_dir do |path|
create_file('README.md', "# README\n")
git = Git.init('.')
git.add
git.commit(expected_commit_message)
commits = git.log(1)
actual_commit_message = commits.first.message
assert_equal(expected_commit_message, actual_commit_message)
end
end
end

[8]ページ先頭

©2009-2025 Movatter.jp