@@ -515,3 +515,86 @@ func Test_ViewRun_WithoutUsername(t *testing.T) {
515515 assert .Equal (t , "" , stderr .String ())
516516 reg .Verify (t )
517517}
518+
519+ func Test_ViewRun_HandlesSpecialCharacters (t * testing.T ) {
520+ tests := []struct {
521+ name string
522+ opts * ViewOptions
523+ repoName string
524+ stdoutTTY bool
525+ wantOut string
526+ wantStderr string
527+ wantErr bool
528+ }{
529+ {
530+ name : "nontty" ,
531+ wantOut : heredoc .Doc (`
532+ name: OWNER/REPO
533+ description: Some basic special characters " & / < > '
534+ --
535+ # < is always > than & ' and "
536+ ` ),
537+ },
538+ {
539+ name : "no args" ,
540+ stdoutTTY : true ,
541+ wantOut : heredoc .Doc (`
542+ OWNER/REPO
543+ Some basic special characters " & / < > '
544+
545+
546+ # < is always > than & ' and "
547+
548+
549+
550+ View this repository on GitHub: https://github.com/OWNER/REPO
551+ ` ),
552+ },
553+ }
554+ for _ , tt := range tests {
555+ if tt .opts == nil {
556+ tt .opts = & ViewOptions {}
557+ }
558+
559+ if tt .repoName == "" {
560+ tt .repoName = "OWNER/REPO"
561+ }
562+
563+ tt .opts .BaseRepo = func () (ghrepo.Interface , error ) {
564+ repo , _ := ghrepo .FromFullName (tt .repoName )
565+ return repo , nil
566+ }
567+
568+ reg := & httpmock.Registry {}
569+ reg .Register (
570+ httpmock .GraphQL (`query RepositoryInfo\b` ),
571+ httpmock .StringResponse (`
572+ { "data": {
573+ "repository": {
574+ "description": "Some basic special characters \" & / < > '"
575+ } } }` ))
576+ reg .Register (
577+ httpmock .REST ("GET" , fmt .Sprintf ("repos/%s/readme" , tt .repoName )),
578+ httpmock .StringResponse (`
579+ { "name": "readme.md",
580+ "content": "IyA8IGlzIGFsd2F5cyA+IHRoYW4gJiAnIGFuZCAi"}` ))
581+
582+ tt .opts .HttpClient = func () (* http.Client , error ) {
583+ return & http.Client {Transport : reg }, nil
584+ }
585+
586+ io , _ , stdout , stderr := iostreams .Test ()
587+ tt .opts .IO = io
588+
589+ t .Run (tt .name , func (t * testing.T ) {
590+ io .SetStdoutTTY (tt .stdoutTTY )
591+
592+ if err := viewRun (tt .opts ); (err != nil ) != tt .wantErr {
593+ t .Errorf ("viewRun() error = %v, wantErr %v" , err , tt .wantErr )
594+ }
595+ assert .Equal (t , tt .wantStderr , stderr .String ())
596+ assert .Equal (t , tt .wantOut , stdout .String ())
597+ reg .Verify (t )
598+ })
599+ }
600+ }
0 commit comments