Skip to content

fix(wp): handling of CR characters#2189

Merged
sjinks merged 1 commit into
trunkfrom
fix/tty-newline
May 8, 2025
Merged

fix(wp): handling of CR characters#2189
sjinks merged 1 commit into
trunkfrom
fix/tty-newline

Conversation

@sjinks
Copy link
Copy Markdown
Member

@sjinks sjinks commented Jan 11, 2025

Description

This PR strips CR characters from the input stream, making --prompt option work.

Ref: pbq1wL-1LP#comment-1898

Pull request checklist

New release checklist

Steps to Test

Try vip @env -y -- wp option update --prompt command to ensure they work.

@sjinks sjinks self-assigned this Jan 11, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 11, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sjinks
Copy link
Copy Markdown
Member Author

sjinks commented Jan 11, 2025

The alternative is to ignore CR characters in cron-control-runner's TTY:

diff --git a/remote/remote.go b/remote/remote.go
index 4e81932..7fdabb7 100644
--- a/remote/remote.go
+++ b/remote/remote.go
@@ -32,6 +32,7 @@ import (
        "github.com/hashicorp/go-retryablehttp"
        "github.com/howeyc/fsnotify"
        "golang.org/x/net/websocket"
+       "golang.org/x/sys/unix"
        "golang.org/x/term"
 )
 
@@ -440,6 +441,16 @@ func processShutdown(conn net.Conn, wpcli *wpCLIProcess) {
        wpcli.padlock.Unlock()
 }
 
+func setPtyToIgnoreCR(fd int) error {
+       termios, err := unix.IoctlGetTermios(fd, unix.TCGETS)
+       if err == nil {
+               termios.Iflag |= unix.IGNCR
+               return unix.IoctlSetTermios(fd, unix.TCSETS, termios)
+       }
+
+       return err
+}
+
 func processTCPConnectionData(conn net.Conn, wpcli *wpCLIProcess) {
        data := make([]byte, 8192)
        var size, written int
@@ -775,6 +786,10 @@ func runWpCliCmdRemote(conn net.Conn, GUID string, rows uint16, cols uint16, wpC
        }
        defer func() { _ = term.Restore(int(tty.Fd()), prevState) }()
 
+       if e := setPtyToIgnoreCR(int(tty.Fd())); e != nil {
+               return fmt.Errorf("runWpCliCmdRemote: error setting the WP CLI tty to send LF: %s", e.Error())
+       }
+
        readFile, err := os.OpenFile(logFileName, os.O_RDONLY, os.ModeCharDevice)
        if nil != err {
                conn.Close()

@sjinks sjinks changed the title fix(wp): handling of CR caharacters fix(wp): handling of CR characters Jan 11, 2025
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been marked stale because it has been open for 60 days with no activity. If there is no activity within 7 days, it will be closed.

This is an automation to keep pull requests manageable and actionable and is not a comment on the quality of this pull request nor on the work done so far. Closed PRs are still valuable to the project and their branches are preserved.

@sonarqubecloud
Copy link
Copy Markdown

@sjinks sjinks requested a review from Copilot April 16, 2025 00:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@sjinks sjinks force-pushed the fix/tty-newline branch from 0ea75a0 to 972ed57 Compare May 8, 2025 16:48
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2025

@sjinks sjinks merged commit 11c1ccd into trunk May 8, 2025
19 checks passed
@sjinks sjinks deleted the fix/tty-newline branch May 8, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants