1
0
mirror of https://github.com/golang/go synced 2024-10-04 12:21:26 -06:00
Commit Graph

557 Commits

Author SHA1 Message Date
Rob Pike
0a5508c692 various: we don't cast, we convert
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5437142
2011-12-05 19:40:52 -08:00
Russ Cox
2666b815a3 use new strconv API
All but 3 cases (in gcimporter.go and hixie.go)
are automatic conversions using gofix.

No attempt is made to use the new Append functions
even though there are definitely opportunities.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5447069
2011-12-05 15:48:46 -05:00
Luuk van Dijk
40b2fe004f gc: changes in export format in preparation of inlining.
Includes minimal change to gcimporter to keep it working,

R=rsc, gri
CC=golang-dev
https://golang.org/cl/5431046
2011-12-05 14:40:19 -05:00
Russ Cox
dcf1d7bc0e gofmt -s misc src
R=golang-dev, bradfitz, gri
CC=golang-dev
https://golang.org/cl/5451079
2011-12-02 14:14:25 -05:00
Gustav Paul
bd9dc3d55f exp/ssh: allow for msgUserAuthBanner during authentication
The SSH spec allows for the server to send a banner message to the client at any point during the authentication process. Currently the ssh client auth types all assume that the first response from the server after issuing a userAuthRequestMsg will be one of a couple of possible authentication success/failure messages. This means that client authentication breaks if the ssh server being connected to has a banner message configured.

This changeset refactors the noneAuth, passwordAuth and publickeyAuth types' auth() function and allows for msgUserAuthBanner during authentication.

R=golang-dev, rsc, dave, agl
CC=golang-dev
https://golang.org/cl/5432065
2011-12-02 10:34:42 -05:00
Gustav Paul
fad57c0c03 exp/ssh: export type signal. Renamed to Signal
R=dave, agl, rsc, golang-dev, n13m3y3r
CC=golang-dev
https://golang.org/cl/5450059
2011-12-01 14:06:15 -05:00
Adam Langley
bac7bc55a6 Add a []byte argument to hash.Hash to allow an allocation to be saved.
This is the result of running `gofix -r hashsum` over the tree, changing
the hash function implementations by hand and then fixing a couple of
instances where gofix didn't catch something.

The changed implementations are as simple as possible while still
working: I'm not trying to optimise in this CL.

R=rsc, cw, rogpeppe
CC=golang-dev
https://golang.org/cl/5448065
2011-12-01 12:35:37 -05:00
Dave Cheney
c4d0ac0e2f exp/ssh: add Std{in,out,err}Pipe methods to Session
R=gustav.paul, cw, agl, rsc, n13m3y3r
CC=golang-dev
https://golang.org/cl/5433080
2011-12-01 08:30:16 -02:00
Dave Cheney
0e62c75b9d undo CL 5436056 / 03560deae933
Remove the accidentally exported net.Listener

««« original CL description
exp/ssh: remove unused forwarding methods in Server Listener

R=agl, rsc
CC=golang-dev
https://golang.org/cl/5436056

»»»

R=agl, rsc
CC=golang-dev
https://golang.org/cl/5437090
2011-11-30 17:14:03 -05:00
Russ Cox
8dce57e169 os: new FileInfo, FileMode types + update tree
R=golang-dev, r, r, gri, bradfitz, iant, iant, nigeltao, n13m3y3r
CC=golang-dev
https://golang.org/cl/5416060
2011-11-30 12:04:16 -05:00
Russ Cox
03823b881c use new time API
R=bradfitz, gri, r, dsymonds
CC=golang-dev
https://golang.org/cl/5390042
2011-11-30 12:01:46 -05:00
Gustav Paul
c6691d1fb4 exp/ssh: Add Start(cmd string) and Signal(sig string) to Session. Rename Exec to Run.
Exec() has been renamed to Run() in keeping with the os/exec API.

Added func (*Session) Start(cmd string) which starts a remote process but unlike Run() doesn't wait for it to finish before returning.

Run() has been refactored to use Start internally. Its really just a refactoring, no new code but some extra functionality was won.

Also added func (*Session) Signal(sig signal) which sends a UNIX signal to a remote process. This is espcially useful in conjunction with Start() as the two allow you to start a remote process, monitor its stdout/stderr, and send it a TERM/HUP/etc signal when you want it to close.

R=dave, rsc, agl, bradfitz, n13m3y3r, gustavo
CC=golang-dev
https://golang.org/cl/5437058
2011-11-29 12:26:39 -05:00
Dave Cheney
4cc64bd5bf exp/ssh: move openChan to NewSession
openChan was only being called by NewSession, Dial has
its own version.

R=gustav.paul, agl, rsc
CC=golang-dev
https://golang.org/cl/5435071
2011-11-28 15:42:47 -05:00
Dave Cheney
b57bb9282e exp/ssh: add safeString error sanitiser
R=huin, agl, gustav.paul, cw
CC=golang-dev
https://golang.org/cl/5399044
2011-11-28 12:29:19 -05:00
Dave Cheney
ce7e11997b exp/ssh: fix three shift bugs related to packet lengths
Thanks for Ke Lan for the initial report and investigation.

R=agl, gustav.paul, tg8866, rsc
CC=golang-dev
https://golang.org/cl/5443044
2011-11-28 12:10:16 -05:00
Brad Fitzpatrick
e77099daa2 sql: add Tx.Stmt to use an existing prepared stmt in a transaction
R=rsc
CC=golang-dev
https://golang.org/cl/5433059
2011-11-28 11:00:32 -05:00
Gustav Paul
23227f3d63 exp/ssh: fix misleading spelling mistake in comment
R=dave, agl, rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5431089
2011-11-28 10:45:52 -05:00
Gustav Paul
d859d7deee exp/ssh: messages now contain remote channel's id instead of local id
According to http://www.ietf.org/rfc/rfc4254.txt most channel messages contain the channel id of the recipient channel, not the sender id. This allows the recipient connection multiplexer to route the message to the correct channel.

This changeset fixes several messages that incorrectly send the local channel id instead of the remote channel's id.

While sessions were being created and closed in sequence channels in the channel pool were freed and reused on the server side of the connection at the same rate as was done on the client, so the channel local and remote channel ids always corresponded. As soon as I had concurrent sessions on the same clientConn the server started to complain of 'uknown channel id N' where N is the local channel id, which is actually paired with server channel id K.

R=golang-dev, dave, rsc, agl
CC=golang-dev
https://golang.org/cl/5433063
2011-11-27 09:59:20 -05:00
Benny Siegert
5519b5d716 exp/sql/driver: Correct package name in comment.
IIRC, package sql used to be called db. There was one occurrence
of the old name in a comment.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5431075
2011-11-25 10:57:10 -05:00
Dave Cheney
f2c858749a exp/ssh: add simple tcpip.go functional tests
R=rsc, agl, n13m3y3r, bradfitz
CC=golang-dev
https://golang.org/cl/5385041
2011-11-23 09:38:11 -05:00
Dave Cheney
d5514120b1 exp/ssh: remove unused forwarding methods in Server Listener
R=agl, rsc
CC=golang-dev
https://golang.org/cl/5436056
2011-11-23 09:35:01 -05:00
Brad Fitzpatrick
750d0e33fb sql: more driver docs & tests; no functional changes
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5415055
2011-11-20 14:56:49 -05:00
Dave Cheney
fb57134d47 exp/ssh: alter Session to match the exec.Cmd API
This CL inverts the direction of the Stdin/out/err members of the
Session struct so they reflect the API of the exec.Cmd. In doing so
it borrows heavily from the exec package.

Additionally Shell now returns immediately, wait for completion using
Wait. Exec calls Wait internally and so blocks until the remote
command is complete.

Credit to Gustavo Niemeyer for the impetus for this CL.

R=rsc, agl, n13m3y3r, huin, bradfitz
CC=cw, golang-dev
https://golang.org/cl/5322055
2011-11-20 11:46:35 -05:00
Nigel Tao
dbb591d8da exp/gui: delete exp/gui and exp/gui/x11. They are moving to
x-go-binding.googlecode.com.

R=rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/5406041
2011-11-20 21:56:17 +11:00
John Beisley
0e60804b4a exp/ssh: Add support for (most) of the ciphers from RFC4253, RFC4344 and RFC4345.
R=dave, agl, taruti, rsc, r
CC=golang-dev
https://golang.org/cl/5342057
2011-11-18 12:56:57 -05:00
Dmitriy Vyukov
151bcb11a8 exp/terminal: fix Makefile formatting for deps.bash
deps.bash does not understand current format,
so make.bash fails (with MAKEFLAGS=-j20).

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5410046
2011-11-18 15:30:36 +03:00
Gustavo Niemeyer
558d055352 exp/terminal: fix build after os.Errno changes
Also include exp/terminal in linux build so such failures
are noticed.

R=rsc
CC=golang-dev
https://golang.org/cl/5416044
2011-11-18 01:12:57 -02:00
Alex Brainman
3ec82f6e09 exp/ssh: change test listen address, also exit test if fails
R=golang-dev, rsc
CC=dave, golang-dev
https://golang.org/cl/5364061
2011-11-17 11:20:42 +11:00
Russ Cox
8c6461bcb1 exp/ssh: fix test?
Fixes use of c after Dial failure (causes crash).
May fix Dial failure by listening to 127.0.0.1:0
instead of 0.0.0.0:0 (tests should only listen on
localhost).

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5395052
2011-11-16 18:13:50 -05:00
Dave Cheney
00f9b7680a exp/ssh: fix unmarshal test
Ensure that empty NameLists always return
a zero length []string, not nil.

In practice NameLists are only used in a few
message types and always consumed by a for
range function so the difference between nil
and []string{} is not significant.

Also, add exp/ssh to pkg/Makefile as suggested
by rsc.

R=rsc, agl
CC=golang-dev
https://golang.org/cl/5400042
2011-11-16 10:19:56 -05:00
Yasuhiro Matsumoto
5e5c5c2789 exp/sql: NumInput() allow -1 to ignore checking.
Some database driver can't get number of parameters.
For example:
        http://support.microsoft.com/kb/240205/en-us
So, added way to ignore checking number of parameters with return -1.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5376091
2011-11-15 16:29:43 -08:00
Brad Fitzpatrick
5b7827ec07 sql: document that for drivers, io.EOF means no more rows
This was used in the sql package + tests, but never
documented.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5372107
2011-11-15 14:29:45 -08:00
Brad Fitzpatrick
0a8005c772 sql: add DB.Close, fix bugs, remove Execer on Driver (only Conn)
R=rsc
CC=golang-dev
https://golang.org/cl/5372099
2011-11-14 10:48:26 -08:00
Russ Cox
c017a8299f syscall: use error
- syscall (not os) now defines the Errno type.
- the low-level assembly functions Syscall, Syscall6, and so on
  return Errno, not uintptr
- syscall wrappers all return error, not uintptr.

R=golang-dev, mikioh.mikioh, r, alex.brainman
CC=golang-dev
https://golang.org/cl/5372080
2011-11-13 22:44:52 -05:00
Dave Cheney
7af553ab52 exp/ssh: add direct-tcpip client support
This CL adds experimental support for making proxied
net.Conn connections via the remote server.

nb. Functional tests exist for this feature but CL
5320053 or similar needs to be committed to support them.

R=rsc, agl, n13m3y3r
CC=cw, golang-dev, huin
https://golang.org/cl/5371081
2011-11-13 21:05:35 -05:00
Dave Cheney
34466a1491 exp/ssh: add client functional tests
Requires CL 5373055

R=rsc, agl, n13m3y3r
CC=golang-dev
https://golang.org/cl/5320053
2011-11-13 20:58:51 -05:00
Dave Cheney
59a92cde3d exp/ssh: use ClientConfig.rand() for publickey authentication
Closes TODO from 5373055

R=agl
CC=golang-dev
https://golang.org/cl/5375081
2011-11-13 20:57:15 -05:00
Dave Cheney
3ee171d174 exp/ssh: add client side support for publickey auth
client.go/client_auth.go:
* add support for publickey key auth using the interface
  outlined by rsc in the previous auth CL

client_auth_test.go:
* password and publickey tests against server.go

common.go/server.go:
* move some helper methods from server.go into common.go
* generalise serializeRSASignature

R=rsc, agl, huin
CC=cw, golang-dev, n13m3y3r
https://golang.org/cl/5373055
2011-11-13 14:48:22 -05:00
Dave Cheney
90ec203318 exp/ssh: ensure initial window advertisement is not lost
Some remote servers send a 0 window size in the channel
open confirm msg, others send a non zero window size. Make
sure this initial advertisement is not lost.

R=agl, rsc, cw
CC=golang-dev
https://golang.org/cl/5372083
2011-11-13 12:13:46 -05:00
Adam Langley
252ef18d04 exp/terminal: rename shell to terminal and add SetSize
It was never really a shell, but the name carried
over from SSH's ServerShell.

Two small functional changes:

Add SetSize, which allows the size of the terminal
to be changed in response, say, to an SSH message.

Don't write the prompt if there's already something
on the current line.

R=rsc
CC=golang-dev
https://golang.org/cl/5376066
2011-11-11 14:04:33 -05:00
Adam Langley
d08f57e68c exp/terminal: rename terminal.go to util.go
(This is part of removing the duplicate code between exp/terminal and
exp/ssh, but hg is having a very hard time keeping up so I'm doing it
in small steps.)

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/5373061
2011-11-11 11:18:45 -05:00
Rob Pike
30aa701fec renaming_2: gofix -r go1pkgrename src/pkg/[a-l]*
R=rsc
CC=golang-dev
https://golang.org/cl/5358041
2011-11-08 15:40:58 -08:00
Dave Cheney
1170a6460f exp/ssh: improved client authentication support
This CL adds an API for handling the various SSH
authenticaton methods. None and password continue
to be the only supported methods.

R=bradfitz, agl, n13m3y3r, rsc, cw
CC=golang-dev
https://golang.org/cl/5328045
2011-11-07 12:37:05 -05:00
Luuk van Dijk
aac144b120 gc: detect type switch variable not used cases.
Fixes #873
Fixes #2162

R=rsc
CC=golang-dev
https://golang.org/cl/5341043
2011-11-04 17:03:50 +01:00
Gustavo Niemeyer
f2dc50b48d html,bzip2,sql: rename Error methods that return error to Err
There are three classes of methods/functions called Error:

a) The Error method in the just introduced error interface
b) Error methods that create or report errors (http.Error, etc)
c) Error methods that return errors previously associated with
   the receiver (Tokenizer.Error, rows.Error, etc).

This CL introduces the convention that methods in case (c)
should be named Err.

The reasoning for the change is:

- The change differentiates the two kinds of APIs based on
  names rather than just on signature, unloading Error a bit
- Err is closer to the err variable name that is so commonly
  used with the intent of verifying an error
- Err is shorter and thus more convenient to be used often
  on error verifications, such as in iterators following the
  convention of the sql package.

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/5327064
2011-11-04 09:50:20 -04:00
Rob Pike
5cb4a15320 html,log,math: renamings
This is Go 1 package renaming CL #2.
This one merely moves the source; the import strings will be
changed after the next weekly release.

exp/template/html -> html/template
big -> math/big
cmath -> math/cmplx
rand -> math/rand
syslog -> log/syslog

The only edits are in Makefiles and deps.bash.

Note that this CL moves exp/template/html out of exp. I decided
to do that so all the renamings can be done together, even though
the API (and that of template, for that matter) is still fluid.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5332053
2011-11-03 12:42:57 -07:00
Russ Cox
965845a86d all: sort imports
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5319072
2011-11-02 15:54:16 -04:00
Brad Fitzpatrick
8089e57812 exp/sql: finish transactions, flesh out types, docs
Fixes #2328 (float, bool)

R=rsc, r
CC=golang-dev
https://golang.org/cl/5294067
2011-11-02 11:46:04 -07:00
Russ Cox
492098eb75 all: rename os.Error to error in various non-code contexts
R=adg
CC=golang-dev
https://golang.org/cl/5328062
2011-11-01 22:58:09 -04:00
Russ Cox
c2049d2dfe src/pkg/[a-m]*: gofix -r error -force=error
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5322051
2011-11-01 22:04:37 -04:00
Russ Cox
c93b6a1756 exp/ebnf: manual fixup for error
(The definition of ErrorList is in another file, so gofix
has no hope of getting this right.)

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5330043
2011-11-01 21:49:33 -04:00
Russ Cox
e67d3c44f7 exp/types: add error type to universe
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/5327051
2011-11-01 21:47:33 -04:00
Russ Cox
7b04471dfa gopack: change archive file name length back to 16
This CL grew the archive file name length from 16 to 64:

        changeset:   909:58574851d792
        user:        Russ Cox <rsc@golang.org>
        date:        Mon Oct 20 13:53:56 2008 -0700

Back then, every x.go file in a package became an x.6 file
in the archive.  It was important to be able to allow the
use of long Go source file names, hence the increase in size.

Today, all Go source files compile into a single _go_.6 file
regardless of their names, so the archive file name length
no longer needs to be long.  The longer name causes some
problems on Plan 9, where the native archive format is the
same but with 16-byte names, so revert back to 16.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5333050
2011-11-01 00:29:16 -04:00
Scott Lawrence
cae23f036a template: fix error checking on execute without parse
Fixed error checking in exec.go to give a sensible error message when
execution is attempted before a successful parse (rather than an
outright panic).

R=r
CC=golang-dev
https://golang.org/cl/5306065
2011-10-31 16:07:17 -07:00
Marcel van Lohuizen
eef7809193 exp/norm: fixed bug that creeped in with moving to the new
regexp, which caused the last line of a test block to be ignored.

R=r, rsc
CC=golang-dev
https://golang.org/cl/5177052
2011-10-31 10:58:04 +01:00
Dave Cheney
0f6b80c694 exp/ssh: fix length header leaking into channel data streams.
The payload of a data message is defined as an SSH string type,
which uses the first four bytes to encode its length. When channelData
and channelExtendedData were added I defined Payload as []byte to
be able to use it directly without a string to []byte conversion. This
resulted in the length data leaking into the payload data.

This CL fixes the bug, and restores agl's original fast path code.

Additionally, a bug whereby s.lock was not released if a packet arrived
for an invalid channel has been fixed.

Finally, as they were no longer used, I have removed
the channelData and channelExtedendData structs.

R=agl, rsc
CC=golang-dev
https://golang.org/cl/5330053
2011-10-29 14:22:30 -04:00
Russ Cox
c1178aae86 strconv: use better errors than os.EINVAL, os.ERANGE
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/5327052
2011-10-27 19:46:31 -07:00
Russ Cox
32f3770ec5 pkg: remove .String() from some print arguments
I found these by adding a check to govet, but the check
produces far too many false positives to be useful.
Even so, these few seem worth cleaning up.

R=golang-dev, bradfitz, iant
CC=golang-dev
https://golang.org/cl/5311067
2011-10-27 18:03:52 -07:00
Russ Cox
c945f77f41 exp/norm: use rune
Nothing terribly interesting here. (!)

Since the public APIs are all in terms of UTF-8,
the changes are all internal only.

R=mpvl, gri, r
CC=golang-dev
https://golang.org/cl/5309042
2011-10-25 22:26:12 -07:00
Russ Cox
4911622055 exp/template/html: use rune
Nothing terribly interesting here.

R=mikesamuel, nigeltao, r
CC=golang-dev
https://golang.org/cl/5307044
2011-10-25 22:22:26 -07:00
Russ Cox
28c06182c0 exp/winfsnotify: fix govet-found bug
R=golang-dev, hectorchu
CC=golang-dev
https://golang.org/cl/5304044
2011-10-25 22:21:14 -07:00
Russ Cox
5be33e9543 godoc, exp/ebnf, exp/types, go/scanner, scanner: use rune
API question: is a scanner token an int or a rune?

Since the rune is the common case and the token values
are the special (negative) case, I chose rune.  But it could
easily go the other way.

R=gri
CC=golang-dev
https://golang.org/cl/5301049
2011-10-25 22:20:20 -07:00
Russ Cox
f4568882eb exp/types: add rune to universe
R=gri
CC=golang-dev
https://golang.org/cl/5295045
2011-10-25 22:19:09 -07:00
Dave Cheney
5791233461 exp/ssh: introduce Session to replace Cmd for interactive commands
This CL replaces the Cmd type with a Session type representing
interactive channels. This lays the foundation for supporting
other kinds of channels like direct-tcpip or x11.

client.go:
* replace chanlist map with slice.
* generalize stdout and stderr into a single type.
* unexport ClientChan to clientChan.

doc.go:
* update ServerConfig/ServerConn documentation.
* update Client example for Session.

message.go:
* make channelExtendedData more like channelData.

session.go:
* added Session which replaces Cmd.

R=agl, rsc, n13m3y3r, gustavo
CC=golang-dev
https://golang.org/cl/5302054
2011-10-24 19:13:55 -04:00
Dave Cheney
8bfb217123 exp/ssh: server cleanups
server.go/channel.go:
* rename Server to ServerConfig to match Client.
* rename ServerConnection to ServeConn to match Client.
* add Listen/Listener.
* ServerConn.Handshake(), general cleanups.

client.go:
* fix bug where fmt.Error was not assigned to err

R=rsc, agl
CC=golang-dev
https://golang.org/cl/5265049
2011-10-21 11:04:28 -04:00
Dave Cheney
792a55f5db exp/ssh: add experimental ssh client
Requires CL 5285044

client.go:
* add Dial, ClientConn, ClientChan, ClientConfig and Cmd.

doc.go:
* add Client documentation.

server.go:
* adjust for readVersion change.

transport.go:
* return an os.Error not a bool from readVersion.

R=rsc, agl, n13m3y3r
CC=golang-dev
https://golang.org/cl/5162047
2011-10-20 15:44:45 -04:00
Hector Chu
9e1a2adf07 exp/winfsnotify: fix test
R=alex.brainman, mattn.jp
CC=golang-dev
https://golang.org/cl/5311047
2011-10-20 08:10:58 +01:00
Russ Cox
bb8c4ed22a exp/types: fix crash in parseBasicType on unknown type
R=gri
CC=golang-dev
https://golang.org/cl/5302044
2011-10-19 12:49:01 -04:00
Mikio Hara
e13635c1e0 os/inotify: move to exp/inotify
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5295044
2011-10-19 10:54:45 +09:00
Nigel Tao
98e723ed09 html: fix escape_test.go for CSS escaper change 5306042.
R=mikesamuel
CC=golang-dev
https://golang.org/cl/5313044
2011-10-19 10:54:04 +11:00
Mike Samuel
fc3ce34903 exp/template/html: fix bug in cssEscaper
cssEscaper escapes using the CSS convention: `\` + hex + optional-space

It outputs the space when the escape could be followed by
a hex digit to distinguish a "\na" from "\u00aa".

It did not output a space when the escape is followed by a space
character so did not distinguish "\n " from "\n".

Currently when doing lookahead, it does not distinguish spaces that
will be escaped later by the same function from ones that will not.
This is correct but suboptimal.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5306042
2011-10-18 17:01:42 -05:00
Hector Chu
7ecf6c997e exp/winfsnotify: filesystem watcher for Windows
R=rsc, alex.brainman, bradfitz
CC=bsiegert, go.peter.90, golang-dev
https://golang.org/cl/4188047
2011-10-18 21:09:58 +01:00
Adam Langley
7bc4f8de0f exp/terminal: split terminal handling from exp/ssh
This change splits terminal handling from exp/ssh, as suggested
several times in the ssh code review.

shell.go and shell_test.go are copies from exp/ssh with minimal
changes, so don't need another full review. A future CL will remove
that code from exp/ssh.

R=bradfitz, r, dave, rsc
CC=golang-dev
https://golang.org/cl/5278049
2011-10-18 12:58:57 -04:00
Dave Cheney
ec158f77bd exp/ssh: general cleanups for client support
common.go:
* simplify findAgreedAlgorithms.
* add channelExtendedData support.

messages.go:
* add clientExtendedData.

server.go:
*  use simplified findAgreedAlgorithms.

server_shell.go:
* fix shadowed err return value.

transport.go:
* introduce separate cipher, mac and compression for each direction.
* added filteredConn and packetWriter interfaces.
* newTransport requires a source of randomness.

R=golang-dev, agl, rsc
CC=golang-dev
https://golang.org/cl/5285044
2011-10-18 12:54:48 -04:00
Russ Cox
313c8224d5 gofix -r mapdelete
R=golang-dev, r, adg, r, cw
CC=golang-dev
https://golang.org/cl/5266045
2011-10-18 09:56:34 -04:00
Russ Cox
d2b73730b7 exp/template/html: do not depend on reflection on internal fields
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5286049
2011-10-17 18:23:59 -04:00
Robert Griesemer
812249fe5e gotype: move to exp/gotype per Go 1 plan
R=r, dsymonds
CC=golang-dev
https://golang.org/cl/5269043
2011-10-13 16:36:53 -07:00
Robert Griesemer
29c2838cb4 go/types: move to exp/types per Go 1 plan
This package is only used by gotype at the moment.

R=rsc, r
CC=golang-dev
https://golang.org/cl/5266042
2011-10-13 15:41:48 -07:00
Russ Cox
06862617c1 build: fix for new return restriction
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5257057
2011-10-13 12:17:18 -04:00
Robert Hencke
c50182480d pkg: fix incorrect prints found by govet
R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/5266041
2011-10-13 13:34:01 +11:00
Christopher Wedgwood
707e5acd71 updates: append(y,[]byte(z)...) -> append(y,z...)"
(more are possible but omitted for now as they are part of
specific tests where rather than changing what is there we
should probably expand the tests to cover the new case)

R=rsc, dvyukov
CC=golang-dev
https://golang.org/cl/5247058
2011-10-12 13:42:04 -07:00
Robert Griesemer
187c3536a8 exp/datafmt: delete per Go 1 plan
R=r, bradfitz
CC=golang-dev
https://golang.org/cl/5249055
2011-10-11 17:52:37 -07:00
Robert Griesemer
e58a77809d ebnf, ebnflint: move under exp
pkg/ebnf -> pkg/exp/ebnf
cmd/ebnflint -> pkg/exp/ebnflint

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5188042
2011-10-11 17:43:10 -07:00
Brad Fitzpatrick
9b8cdad8aa exp/spdy: move http/spdy to exp/spdy
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5238051
2011-10-11 16:45:01 -07:00
Marcel van Lohuizen
9a8da9d499 exp/norm: LastBoundary is used in preparation for an append operation. It seems
therefore unlikely that there is a good use for its string version
LastBoundaryInString. Yet, the implemenation of this method would complicate
things a bit as it would require the introduction for another interface and
some duplication of code. Removing it seems a better choice.

R=r
CC=golang-dev
https://golang.org/cl/5182044
2011-10-05 14:36:02 -07:00
Marcel van Lohuizen
5844fc1b21 exp/norm: introduced input interface to implement string versions
of methods.

R=r, mpvl
CC=golang-dev
https://golang.org/cl/5166045
2011-10-05 10:44:11 -07:00
Mike Samuel
b0cddb98b9 exp/template/html: avoid redundant escaping directives.
This is a possible optimization.  I'm not sure the complexity is worth it.
The new benchmark in escape_test is 46us without and 35us with the optimization.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5168041
2011-09-29 21:31:41 -07:00
Mike Samuel
530719c06f exp/template/html: simplify URL filtering
This removes a few cases from escapeAction and clarifies the
responsibilities of urlFilter which no longer does any
escaping or normalization.  It is now solely a filter.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5162043
2011-09-29 18:09:11 -07:00
Brad Fitzpatrick
357f2cb1a3 exp/sql{,/driver}: new database packages
R=gustavo, rsc, borman, dave, kevlar, nigeltao, dvyukov, kardianos, fw, r, r, david.crawshaw
CC=golang-dev
https://golang.org/cl/4973055
2011-09-29 16:12:21 -07:00
Mike Samuel
f17e3d2288 exp/template/html: handle custom attrs and HTML5 embedded elements.
HTML5 allows embedded SVG and MathML.
Code searches show SVG is used for graphing.

This changes transition to deal with constructs like
   <svg xmlns:xlink="http://www.w3.org/1999/xlink">
It changes attr and clients to call a single function that combines
the name lookup and "on" prefix check to determine an attribute
value type given an attribute name.

That function uses heuristics to recognize that
     xlink:href and svg:href
have URL content, and that data-url is likely contains URL content,
since "javascript:" injection is such a problem.

I did a code search over a closure templates codebase to determine
patterns of custom attribute usage.  I did something like

$ find . -name \*.soy | \
    xargs egrep perl -ne 'while (s/\b((data-|\w+:)\w+)\s*=//) { print "$1\n"; }' | \
    sort | uniq

to produce the list at the bottom.

Filtering that by egrep -i 'src|url|uri' produces

data-docConsumptionUri
data-docIconUrl
data-launchUrl
data-lazySrc
data-pageUrl
data-shareurl
data-suggestServerUrl
data-tweetUrl
g:secondaryurls
g:url

which seem to match all the ones that are likely URL content.
There are some short words that match that heuristic, but I still think it decent since
any custom attribute that has a numeric or enumerated keyword value will be unaffected by
the URL assumption.
Counterexamples from /usr/share/dict:
during, hourly, maturity, nourish, purloin, security, surly

Custom attributes present in existing closure templates codebase:
buzz:aid
data-a
data-action
data-actor
data-allowEqualityOps
data-analyticsId
data-bid
data-c
data-cartId
data-categoryId
data-cid
data-command
data-count
data-country
data-creativeId
data-cssToken
data-dest
data-docAttribution
data-docConsumptionUri
data-docCurrencyCode
data-docIconUrl
data-docId
data-docPrice
data-docPriceMicros
data-docTitle
data-docType
data-docid
data-email
data-entityid
data-errorindex
data-f
data-feature
data-fgid
data-filter
data-fireEvent
data-followable
data-followed
data-hashChange
data-height
data-hover
data-href
data-id
data-index
data-invitable
data-isFree
data-isPurchased
data-jid
data-jumpid
data-launchUrl
data-lazySrc
data-listType
data-maxVisiblePages
data-name
data-nid
data-nodeid
data-numItems
data-numPerPage
data-offerType
data-oid
data-opUsesEquality
data-overflowclass
data-packageName
data-pageId
data-pageUrl
data-pos
data-priceBrief
data-profileIds
data-query
data-rating
data-ref
data-rentalGrantPeriodDays
data-rentalactivePeriodHours
data-reviewId
data-role
data-score
data-shareurl
data-showGeLe
data-showLineInclude
data-size
data-sortval
data-suggestServerType
data-suggestServerUrl
data-suggestionIndex
data-tabBarId
data-tabBarIndex
data-tags
data-target
data-textColor
data-theme
data-title
data-toggletarget
data-tooltip
data-trailerId
data-transactionId
data-transition
data-ts
data-tweetContent
data-tweetUrl
data-type
data-useAjax
data-value
data-width
data-x
dm:index
dm:type
g:aspects
g:decorateusingsecondary
g:em
g:entity
g:groups
g:id
g:istoplevel
g:li
g:numresults
g:oid
g:parentId
g:pl
g:pt
g:rating_override
g:secondaryurls
g:sortby
g:startindex
g:target
g:type
g:url
g:value
ga:barsize
ga:css
ga:expandAfterCharsExceed
ga:initialNumRows
ga:nocancelicon
ga:numRowsToExpandTo
ga:type
ga:unlockwhenrated
gw:address
gw:businessname
gw:comment
gw:phone
gw:source
ng:controller
xlink:href
xml:lang
xmlns:atom
xmlns:dc
xmlns:jstd
xmlns:ng
xmlns:og
xmlns:webstore
xmlns:xlink

R=nigeltao
CC=golang-dev
https://golang.org/cl/5119041
2011-09-28 14:07:48 -07:00
Mike Samuel
582bb30466 exp/template/html: don't normalize '<' in doctypes.
The normalization that prevents element name and comment injection in
  <{{.}}
by converting it to
  &lt;{{.}}
breaks
  <!DOCTYPE html>

Instead of splitting states to have a start of document state and a text
state, I whitelist <!DOCTYPE.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5131051
2011-09-28 13:32:56 -07:00
Mike Samuel
260991ad5f exp/template/html: do not escape the RHS of assignments
In

  {{$x := . | foo}}
  {{$x}}

the first action is a variable assignment that contributes
nothing to the output while the first is a use that needs
to be escaped.

This CL fixes escapeAction to distinguish assignments from
interpolations and to only modify interpolations.

R=nigeltao, r
CC=golang-dev
https://golang.org/cl/5143048
2011-09-27 22:08:14 -07:00
Mike Samuel
0287647b13 exp/template/html: add doc comments for undocumented Err... constants.
Does some TODOs and changes the term "div" in an error message
to "division" to avoid confusion with "<div>".

R=nigeltao, r
CC=golang-dev
https://golang.org/cl/5141047
2011-09-27 13:22:01 -07:00
Rob Pike
f3050dbbb5 exp/ssh: update tag usage to new convention.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5136047
2011-09-27 10:22:42 -07:00
Robert Griesemer
9c643bb3fa exp/norm: fix benchmark bug
- don't use range over string to copy string bytes
- some code simplification

R=mpvl
CC=golang-dev
https://golang.org/cl/5144044
2011-09-26 18:23:21 -07:00
Russ Cox
6c230fbc67 regexp: move to old/regexp, replace with exp/regexp
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5127042
2011-09-26 18:33:13 -04:00
Dave Cheney
aa2a31e6c4 exp/ssh: move common code to common.go
R=agl
CC=golang-dev
https://golang.org/cl/5132041
2011-09-26 10:25:13 -04:00
Mike Samuel
10bf744772 exp/template/html: make sure marshalled JSON can be parsed as JS.
This makes sure that all JS newlines are encoded in JSON.

It also moots a TODO about possibly escaping supplemental codepoints.
I served:

Content-Type: text/javascript;charset=UTF-8

var s = "%s";
document.write("<p>", s, "</p><ol>");
for (var i = 0; i < s.length; i++) {
  document.write("<li>", s.charCodeAt(i).toString(16), "</li>");
}
document.write("</l>");

where %s was replaced with bytes "\xf0\x9d\x84\x9e" to test
straight UTF-8 instead of encoding surrogates separately.

Recent Firefox, Chrome, and Safari all decoded it properly.
I have yet to try it on IE or older versions.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5129042
2011-09-26 02:10:43 -07:00
Mike Samuel
3771415100 exp/template/html: fix infinite loop in escapeText on bad input
The template
    "<a="
caused an infinite loop in escape text.

The change to tTag fixes that and the change to escape.go causes
escapeText to panic on any infinite loop that does not involve
a state cycle.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5115041
2011-09-26 00:56:49 -07:00
Mike Samuel
66cdd02038 exp/template/html: error out on ambiguous unquoted attributes
HTML parsers may differ on whether
<input id= onchange=f(             ends in id's or onchange's value,
<a class=`foo                      ends inside a value,
<input style=font:'Arial'          needs open-quote fixup.

Per
http://www.w3.org/TR/html5/tokenization.html#attribute-value-unquoted-state
this treats the error cases in 8.2.4.40 Attribute value (unquoted) state
as fatal errors.

\> U+0022 QUOTATION MARK (")
\> U+0027 APOSTROPHE (')
\> U+003C LESS-THAN SIGN (<)
\> U+003D EQUALS SIGN (=)
\> U+0060 GRAVE ACCENT (`)
        Parse error. Treat it as per the "anything else" entry below.

and emits ErrBadHTML.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5085050
2011-09-26 00:42:38 -07:00
Mike Samuel
b3d8e6d7f4 exp/template/html: remove TODO comments that have been done or mooted
R=nigeltao
CC=golang-dev
https://golang.org/cl/5128041
2011-09-26 00:10:21 -07:00
Jaroslavas Počepko
10b23e7fc9 syscall: mksyscall_windows.pl to produce packages other than syscall (for example pkg/exp/wingui/zwinapi.go)
R=golang-dev, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/4964074
2011-09-24 10:38:39 +10:00
Mike Samuel
967d68c00a exp/template/html: tighten rules on dynamic attr names.
R=nigeltao
CC=golang-dev
https://golang.org/cl/5076049
2011-09-23 09:25:10 -07:00
Mike Samuel
35819729b8 exp/template/html: elide comments in template source.
When templates are stored in external files, developers often embed
comments to explain&|disable code.

  <!-- Oblique reference to project code name here -->
  {{if .C}}...{{else}}<!-- commented out default -->{{end}}

This unnecessarily increases the size of shipped HTML and can leak
information.

This change elides all comments of the following types:
1. <!-- ... --> comments found in source.
2. /*...*/ and // comments found in <script> elements.
3. /*...*/ and // comments found in <style> elements.

It does not elide /*...*/ or // comments found in HTML attributes:
4. <button onclick="/*...*/">
5. <div style="/*...*/">

I can find no examples of comments in attributes in Closure Templates
code and doing so would require keeping track of character positions
post decode in

  <button onclick="/&#42;...*/">

To prevent token joining, /*comments*/ are JS and CSS comments are
replaced with a whitespace char.
HTML comments are not, but to prevent token joining we could try to
detect cases like
   <<!---->b>
   </<!---->b>
which has a well defined meaning in HTML but will cause a validator
to barf.  This is difficult, and this is a very minor case.
I have punted for now, but if we need to address this case, the best
way would be to normalize '<' in stateText to '&lt;' consistently.

The whitespace to replace a JS /*comment*/ with depends on whether
there is an embedded line terminator since
    break/*
    */foo
    ...
is equivalent to
    break;
    foo
    ...
while
    break/**/foo
    ...
is equivalent to
    break foo;
    ...

Comment eliding can interfere with IE conditional comments.
http://en.wikipedia.org/wiki/Conditional_comment

<!--[if IE 6]>
<p>You are using Internet Explorer 6.</p>
<![endif]-->

/*@cc_on
  document.write("You are using IE4 or higher");
@*/

I have not encountered these in production template code, and
the typed content change in CL 4962067 provides an escape-hatch
if conditional comments are needed.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4999042
2011-09-21 21:38:40 -07:00
Mike Samuel
1f577d26d7 exp/template/html: simplify transition functions
This simplifies transition functions to make it easier to reliably
elide comments in a later CL.

Before:
- transition functions are responsible for detecting special end tags.
After:
- the code to detect special end tags is done in one place.

We were relying on end tags being skipped which meant we were
not noticing comments inside script/style elements that contain no
substitutions.
This change means we will notice all such comments where necessary,
but stripTags will notice none since it does not need to.  This speeds
up stripTags.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5074041
2011-09-21 19:04:41 -07:00
Mike Samuel
1262f6bde7 exp/template/html: fix bug, '<' normalization for text nodes that change context
R=nigeltao
CC=golang-dev
https://golang.org/cl/5080042
2011-09-20 22:55:14 -07:00
Dave Cheney
fd3978552b exp/ssh: refactor halfConnection to transport
This CL generalises the pair of halfConnection members that the
        serverConn holds into a single transport struct that is shared by
        both Server and Client, see also CL 5037047.

        This CL is a replacement for 5040046 which I closed by accident.

R=agl, bradfitz
CC=golang-dev
https://golang.org/cl/5075042
2011-09-20 12:21:50 -04:00
Mike Samuel
3a013f1175 exp/template/html: change transition functions to return indices
Formulaic changes to transition functions in preparation for CL 5074041.
This should be completely semantics preserving.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5091041
2011-09-19 20:52:14 -07:00
Mike Samuel
8bc5ef6cd7 exp/template/html: allow commenting out of actions
Instead of erroring on actions inside comments, use existing escaping
pipeline to quash the output of actions inside comments.

If a template maintainer uses a comment to disable template code:

  {{if .}}Hello, {{.}}!{{end}}

->

  <!--{{if true}}Hello, {{.}}!{{end}}-->

will result in

  <!--Hello, !-->

regardless of the value of {{.}}.

In a later CL, comment elision will result in the entire commented-out
section being dropped from the template output.

Any side-effects in pipelines, such as panics, will still be realized.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5078041
2011-09-19 19:52:31 -07:00
Mike Samuel
533b372280 exp/template/html: define isComment helper
Non semantics-changing refactoring in preparation for comment elision.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5071043
2011-09-19 17:27:49 -07:00
Marcel van Lohuizen
46468357a2 exp/norm: Adopt regexp to exp/regexp semantics.
R=rsc
CC=golang-dev
https://golang.org/cl/5046041
2011-09-19 17:30:19 +02:00
Dave Cheney
03178bb4ad exp/ssh: fix constant in package documentation
R=agl
CC=golang-dev
https://golang.org/cl/5030054
2011-09-19 10:32:11 -04:00
Mike Samuel
b4e1ca25b1 exp/template/html: allow quotes on either side of conditionals and dynamic HTML names
This addresses several use cases:

(1) <h{{.HeaderLevel}}> used to build hierarchical documents.
(2) <input on{{.EventType}}=...> used in widgets.
(3) <div {{" dir=ltr"}}> used to embed bidi-hints.

It also makes sure that we treat the two templates below the same:

<img src={{if .Avatar}}"{{.Avatar}}"{{else}}"anonymous.png"{{end}}>
<img src="{{if .Avatar}}{{.Avatar}}{{else}}anonymous.png{{end}}">

This splits up tTag into a number of sub-states and adds testcases.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5043042
2011-09-18 19:10:15 -07:00
Mike Samuel
52a46bb773 exp/template/html: normalize '<' in text and RCDATA nodes.
The template

  <{{.}}

would violate the structure preservation property if allowed and not
normalized, because when {{.}} emitted "", the "<" would be part of
a text node, but if {{.}} emitted "a", the "<" would not be part of
a text node.

This change rewrites '<' in text nodes and RCDATA text nodes to
'&lt;' allowing template authors to write the common, and arguably more
readable:

    Your price: {{.P1}} < list price {{.P2}}

while preserving the structure preservation property.

It also lays the groundwork for comment elision, rewriting

    Foo <!-- comment with secret project details --> Bar

to

    Foo  Bar

R=nigeltao
CC=golang-dev
https://golang.org/cl/5043043
2011-09-18 12:04:40 -07:00
Mike Samuel
e213a0c0fc exp/template/html: recognize whitespace at start of URLs.
HTML5 uses "Valid URL potentially surrounded by spaces" for
attrs: http://www.w3.org/TR/html5/index.html#attributes-1

    <a href=" {{.}}">

should be escaped to filter out "javascript:..." as data.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5027045
2011-09-18 11:55:14 -07:00
Adam Langley
605e57d8fe exp/ssh: new package.
The typical UNIX method for controlling long running process is to
send the process signals. Since this doesn't get you very far, various
ad-hoc, remote-control protocols have been used over time by programs
like Apache and BIND.

Implementing an SSH server means that Go code will have a standard,
secure way to do this in the future.

R=bradfitz, borman, dave, gustavo, dsymonds, r, adg, rsc, rogpeppe, lvd, kevlar, raul.san
CC=golang-dev
https://golang.org/cl/4962064
2011-09-17 15:57:24 -04:00
Marcel van Lohuizen
a083fd524a exp/norm: reverting to using strings.Repeat, as it doesn't look like exp/regexp
is going to support returning multiple matches for a single repeated group.

R=r, rsc, mpvl
CC=golang-dev
https://golang.org/cl/5014045
2011-09-16 11:28:53 +02:00
Marcel van Lohuizen
1913fdab98 exp/norm: changed trie to produce smaller tables.
Trie now uses sparse block when this makes sense.

R=r, r
CC=golang-dev
https://golang.org/cl/5010043
2011-09-16 11:27:05 +02:00
Mike Samuel
a399040226 exp/template/html: type fixed point computation in template
I found a simple test case that does require doing the fixed point TODO
in computeOutCtx.

I found a way though to do this and simplify away the escapeRange
hackiness that was added in https://golang.org/cl/5012044/

R=nigeltao
CC=golang-dev
https://golang.org/cl/5015052
2011-09-16 00:34:26 -07:00
Mike Samuel
96f9e8837e exp/template/html: moved error docs out of package docs onto error codes
This replaces the errStr & errLine members of context with a single err
*Error, and introduces a number of const error codes, one per
escape-time failure mode, that can be separately documented.

The changes to the error documentation moved from doc.go to error.go
are cosmetic.

R=r, nigeltao
CC=golang-dev
https://golang.org/cl/5026041
2011-09-15 19:05:33 -07:00
Mike Samuel
ce008f8c37 exp/template/html: pre-sanitized content
Not all content is plain text.  Sometimes content comes from a trusted
source, such as another template invocation, an HTML tag whitelister,
etc.

Template authors can deal with over-escaping in two ways.

1) They can encapsulate known-safe content via
   type HTML, type CSS, type URL, and friends in content.go.
2) If they know that the for a particular action never needs escaping
   then they can add |noescape to the pipeline.
   {{.KnownSafeContent | noescape}}
   which will prevent any escaping directives from being added.

This CL defines string type aliases: HTML, CSS, JS, URI, ...
It then modifies stringify to unpack the content type.
Finally it modifies the escaping functions to use the content type and
decline to escape content that does not require it.

There are minor changes to escapeAction and helpers to treat as
equivalent explicit escaping directives such as "html" and "urlquery"
and the escaping directives defined in the contextual autoescape module
and to recognize the special "noescape" directive.

The html escaping functions are rearranged.  Instead of having one
escaping function used in each {{.}} in

    {{.}} : <textarea title="{{.}}">{{.}}</textarea>

a slightly different escaping function is used for each.
When {{.}} binds to a pre-sanitized string of HTML

    `one < <i>two</i> &amp; two < "3"`

we produces something like

     one < <i>two</i> &amp; two < "3" :
     <textarea title="one &lt; two &amp; two &lt; &#34;3&#34;">
       one &lt; &lt;i&gt;two&lt;/i&gt; &amp; two &lt; "3"
     </textarea>

Although escaping is not required in <textarea> normally, if the
substring </textarea> is injected, then it breaks, so we normalize
special characters in RCDATA and do the same to preserve attribute
boundaries.  We also strip tags since developers never intend
typed HTML injected in an attribute to contain tags escaped, but
do occasionally confuse pre-escaped HTML with HTML from a
tag-whitelister.

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/4962067
2011-09-15 08:51:55 -07:00
Mike Samuel
3eb41fbeb6 exp/template/html: render templates unusable when escaping fails
This moots a caveat in the proposed package documentation by
rendering useless any template that could not be escaped.

From https://golang.org/cl/4969078/
> If EscapeSet returns an error, do not Execute the set; it is not
> safe against injection.
r: [but isn't the returned set nil? i guess you don't overwrite the
r: original if there's a problem, but i think you're in your rights to
r: do so]

R=r
CC=golang-dev
https://golang.org/cl/5020043
2011-09-14 20:40:50 -07:00
Mike Samuel
23fab11c47 exp/template/html: flesh out package documentation.
R=nigeltao, r
CC=golang-dev
https://golang.org/cl/4969078
2011-09-14 14:21:20 -07:00
Rob Pike
b47bbecf7a src: fix a couple of govet-discovered errors.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5021042
2011-09-14 13:29:31 -07:00
Mike Samuel
514c9243f2 exp/template/html: check that modified nodes are not shared by templates
R=nigeltao
CC=golang-dev
https://golang.org/cl/5012044
2011-09-14 11:52:03 -07:00
Nigel Tao
aa75bee7a5 image: change the NewXxx functions to take a Rectangle instead of
taking (w, h int).

R=rsc, bsiegert, r
CC=golang-dev
https://golang.org/cl/4964073
2011-09-14 21:39:49 +10:00
Mike Samuel
15d47ce219 exp/template/html: move transition functions to a separate file
This CL moves code but makes no changes otherwise.

R=nigeltao, r
CC=golang-dev
https://golang.org/cl/5012045
2011-09-13 17:53:55 -07:00
Mike Samuel
4c6454aecf exp/template/html: escape {{template}} calls and sets of templates
This adds support for {{template "callee"}} calls.
It recognizes that calls can appear in many contexts.

{{if .ImageURL}}
    <img src="{{.ImageURL}}" alt="{{template "description"}}">
{{else}}
    <p>{{template "description"}}</p>
{{end}}

calls a template in two different contexts, first in an HTML attribute
context, and second in an HTML text context.

Those two contexts aren't very different, but when linking text
to search terms, the escaping context can be materially different:

<a href="/search?q={{template "tags"}}">{{template "tags"}}</a>

This adds API:
EscapeSet(*template.Set, names ...string) os.Error

takes a set of templates and the names of those which might be called
in the default context as starting points.

It changes the escape* functions to be methods of an object which
maintains a conceptual mapping of
(template names*input context) -> output context.

The actual mapping uses as key a mangled name which combines the
template name with the input context.

The mangled name when the input context is the default context is the
same as the unmangled name.

When a template is called in multiple contexts, we clone the template.

{{define "tagLink"}}
  <a href="/search?q={{template "tags"}}">{{template "tags"}}</a>
{{end}}
{{define "tags"}}
  {{range .Tags}}{{.}},{{end}}
{{end}}

given []string{ "foo", "O'Reilly", "bar" } produces

  <a href="/search?q=foo,O%27Reilly,bar">foo,O&#39;Reilly,bar</a>

This involves rewriting the above to something like

{{define "tagLink"}}
  <a href="/search?q={{template "tags$1"}}">{{template "tags"}}</a>
{{end}}
{{define "tags"}}
  {{range .Tags}}{{. | html}},{{end}}
{{end}}
{{define "tags$1"}}
  {{range .Tags}}{{. | urlquery}},{{end}}
{{end}}

clone.go provides a mechanism for cloning template "tags" to produce
"tags$1".

changes to escape.go implement the new API and context propagation
around the call graph.

context.go includes minor changes to support name mangling and
context_test.go tests those.

js.go contains a bug-fix.

R=nigeltao, r
CC=golang-dev
https://golang.org/cl/4969072
2011-09-13 16:57:39 -07:00
Marcel van Lohuizen
efea5d0fb9 exp/norm: Added regression test tool for the standard Unicode test set.
R=r
CC=golang-dev
https://golang.org/cl/4973064
2011-09-13 12:51:48 +02:00
Mike Samuel
0432a23c68 exp/template/html: tolerate '/' ambiguity in JS when it doesn't matter.
Often, division/regexp ambiguity doesn't matter in JS because the next
token is not a slash.

For example, in

  <script>var global{{if .InitVal}} = {{.InitVal}}{{end}}</script>

When there is an initial value, the {{if}} ends with jsCtxDivOp
since a '/' following {{.InitVal}} would be a division operator.
When there is none, the empty {{else}} branch ends with jsCtxRegexp
since a '/' would start a regular expression.  A '/' could result
in a valid program if it were on a new line to allow semicolon
insertion to terminate the VarDeclaration.

There is no '/' though, so we can ignore the ambiguity.

There are cases where a missing semi can result in ambiguity that
we should report.

  <script>
  {{if .X}}var x = {{.X}}{{end}}
  /...{{.Y}}
  </script>

where ... could be /foo/.test(bar) or /divisor.  Disambiguating in
this case is hard and is required to sanitize {{.Y}}.

Note, that in the case where there is a '/' in the script tail but it
is not followed by any interpolation, we already don't care.  So we
are already tolerant of

<script>{{if .X}}var x = {{.X}}{{end}}/a-bunch-of-text</script>

because tJS checks for </script> before looking in /a-bunch-of-text.

This CL
- Adds a jsCtx value: jsCtxUnknown
- Changes joinContext to join contexts that only differ by jsCtx.
- Changes tJS to return an error when a '/' is seen in jsCtxUnknown.
- Adds tests for both the happy and sad cases.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4956077
2011-09-12 16:37:03 -07:00
Mike Samuel
80a5ddbdb1 exp/template/html: fix bug /*/ is not a full JS block comment.
Similar tests for CSS already catch this problem in tCSS.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4967065
2011-09-12 16:01:30 -07:00
Russ Cox
9c6265d339 exp/regexp/syntax: fix invalid input parser crash
Reported by Kyle Lemons.

R=r
CC=golang-dev
https://golang.org/cl/4992045
2011-09-12 14:03:53 -04:00
Marcel van Lohuizen
3e42de29c9 exp/norm: fixed typo. Bug exposed by gomake testtables. Changes did not affect other tests
as this part of Hangul is handled algorithmically.

R=r
CC=golang-dev
https://golang.org/cl/4951074
2011-09-12 10:21:35 +02:00
Nigel Tao
b2b3187f5e exp/template/html: fix JS regexp escape of an empty string.
R=dsymonds
CC=golang-dev, mikesamuel
https://golang.org/cl/4972063
2011-09-12 11:57:34 +10:00
Mike Samuel
1f13423d3e exp/template/html: Grammar rules for HTML comments and special tags.
Augments type context and adds grammatical rules to handle special HTML constructs:
    <!-- comments -->
    <script>raw text</script>
    <textarea>no tags here</textarea>

This CL does not elide comment content.  I recommend we do that but
have not done it in this CL.

I used a codesearch tool over a codebase in another template language.

Based on the below I think we should definitely recognize
  <script>, <style>, <textarea>, and <title>
as each of these appears frequently enough that there are few
template using apps that do not use most of them.

Of the other special tags,
  <xmp>, <noscript>
are used but infrequently, and
  <noframe> and friend, <listing>
do not appear at all.

We could support <xmp> even though it is obsolete in HTML5
because we already have the machinery, but I suggest we do not
support noscript since it is a normal tag in some browser
configurations.

I suggest recognizing and eliding <!-- comments -->
(but not escaping text spans) as they are widely used to
embed comments in template source.  Not eliding them increases
the size of content sent over the network, and risks leaking
code and project internal details.
The template language I tested elides them so there are
no instance of IE conditional compilation directives in the
codebase but that could be a source of confusion.

The codesearch does the equivalent of
$ find . -name \*.file-extension \
  | perl -ne 'print "\L$1\n" while s@<([a-z][a-z0-9])@@i' \
  | sort | uniq -c | sort

The 5 uses of <plaintext> seem to be in tricky code and can be ignored.
The 2 uses of <xmp> appear in the same tricky code and can be ignored.
I also ignored end tags to avoid biasing against unary
elements and threw out some nonsense names since since the
long tail is dominated by uses of < as a comparison operator
in the template languages expression language.

I have added asterisks next to abnormal elements.

  26765 div
   7432 span
   7414 td
   4233 a
   3730 tr
   3238 input
   2102 br
   1756 li
   1755 img
   1674 table
   1388 p
   1311 th
   1064 option
    992 b
    891 label
    714 script *
    519 ul
    446 tbody
    412 button
    381 form
    377 h2
    358 select
    353 strong
    318 h3
    314 body
    303 html
    266 link
    262 textarea *
    261 head
    258 meta
    225 title *
    189 h1
    176 col
    156 style *
    151 hr
    119 iframe
    103 h4
    101 pre
    100 dt
     98 thead
     90 dd
     83 map
     80 i
     69 object
     66 ol
     65 em
     60 param
     60 font
     57 fieldset
     51 string
     51 field
     51 center
     44 bidi
     37 kbd
     35 legend
     30 nobr
     29 dl
     28 var
     26 small
     21 cite
     21 base
     20 embed
     19 colgroup
     12 u
     12 canvas
     10 sup
     10 rect
     10 optgroup
     10 noscript *
      9 wbr
      9 blockquote
      8 tfoot
      8 code
      8 caption
      8 abbr
      7 msg
      6 tt
      6 text
      6 h5
      5 svg
      5 plaintext *
      5 article
      4 shortquote
      4 number
      4 menu
      4 ins
      3 progress
      3 header
      3 content
      3 bool
      3 audio
      3 attribute
      3 acronym
      2 xmp *
      2 overwrite
      2 objects
      2 nobreak
      2 metadata
      2 description
      2 datasource
      2 category
      2 action

R=nigeltao
CC=golang-dev
https://golang.org/cl/4964045
2011-09-09 00:07:40 -07:00
Mike Samuel
4670d9e634 exp/template/html: autoescape actions in HTML style attributes.
This does not wire up <style> elements as that is pending support
for raw text content in CL https://golang.org/cl/4964045/

This CL allows actions to appear in contexts like

selectors:        {{.Tag}}{{.Class}}{{.Id}}
property names:   border-{{.BidiLeadingEdge}}
property values:  color: {{.Color}}
strings:          font-family: "{{font-name}}"
URL strings:      background: "/foo?image={{.ImgQuery}}"
URL literals:     background: url("{{.Image}}")

but disallows actions inside CSS comments and disallows
embedding of JS in CSS entirely.

It is based on the CSS3 lexical grammar with affordances for
common browser extensions including line comments.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4968058
2011-09-09 07:18:20 +10:00
Russ Cox
66b3fabf17 exp/regexp: add MustCompilePOSIX
R=r
CC=golang-dev
https://golang.org/cl/4962060
2011-09-08 15:00:49 -04:00
Russ Cox
21e671dee6 exp/regexp: add CompilePOSIX, more tests
R=r
CC=golang-dev
https://golang.org/cl/4967060
2011-09-08 14:49:51 -04:00
Russ Cox
177dca77e1 exp/regexp/syntax: import all RE2 parse tests + fix bugs
R=r
CC=golang-dev
https://golang.org/cl/4952061
2011-09-08 14:18:02 -04:00
Russ Cox
7df4322114 exp/regexp: leftmost-longest matching
Not exposed in the API yet, but passes tests.

R=r
CC=golang-dev
https://golang.org/cl/4967059
2011-09-08 10:09:25 -04:00
Russ Cox
08ae1a5a23 exp/regexp: bug fixes and RE2 tests
Also add exp/regexp to build (forgot before).

At this point I am very confident in exp/regexp's
behavior.  It should be usable as a drop-in
replacement for regexp now.

Later CLs could introduce a CompilePOSIX
to get at traditional POSIX ``extended regular expressions''
as in egrep and also an re.MatchLongest method to
change the matching mode to leftmost longest
instead of leftmost first.  On the other hand, I expect
very few people to use either.

R=r, r, gustavo
CC=golang-dev
https://golang.org/cl/4990041
2011-09-07 15:48:06 -04:00
Marcel van Lohuizen
d5e24b6975 exp/norm: performance improvements of quickSpan
- fixed performance bug that could lead to O(n^2) behavior
- performance improvement for ASCII case

R=r, r
CC=golang-dev
https://golang.org/cl/4956060
2011-09-05 19:09:20 +02:00
Nigel Tao
2b6d3b498c exp/template/html: string replacement refactoring.
R=mikesamuel
CC=golang-dev
https://golang.org/cl/4968063
2011-09-03 10:30:05 +10:00
Marcel van Lohuizen
2517143957 exp/norm: added Reader and Writer and bug fixes to support these.
Needed to ensure that finding the last boundary does not result in O(n^2)-like behavior.
Now prevents lookbacks beyond 31 characters across the board (starter + 30 non-starters).
composition.go:
- maxCombiningCharacters now means exactly that.
- Bug fix.
- Small performance improvement/ made code consistent with other code.
forminfo.go:
- Bug fix: ccc needs to be 0 for inert runes.
normalize.go:
- A few bug fixes.
- Limit the amount of combining characters considered in FirstBoundary.
- Ditto for LastBoundary.
- Changed semantics of LastBoundary to not consider trailing illegal runes a boundary
  as long as adding bytes might still make them legal.
trie.go:
- As utf8.UTFMax is 4, we should treat UTF-8 encodings of size 5 or greater as illegal.
  This has no impact on the normalization process, but it prevents buffer overflows
  where we expect at most UTFMax bytes.

R=r
CC=golang-dev
https://golang.org/cl/4963041
2011-09-02 12:39:35 +02:00
Mike Samuel
5edeef214d exp/template/html: non-semantics changing tweaks to js{,_test}.go
R=nigeltao
CC=golang-dev
https://golang.org/cl/4962049
2011-09-02 10:28:00 +10:00
Mike Samuel
0253c688d0 exp/template/html: Implement grammar for JS.
This transitions into a JS state when entering any attribute whose
name starts with "on".

It does not yet enter a JS on entry into a <script> element as script
element handling is introduced in another CL.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4968052
2011-09-01 12:03:40 +10:00
Jaroslavas Počepko
95429d82f1 exp/wingui: made compatible with windows/amd64
R=golang-dev, alex.brainman
CC=golang-dev, vcc.163
https://golang.org/cl/4974041
2011-08-31 15:39:50 +10:00
Mike Samuel
22d5f9aae3 exp/template/html: Added handling for URL attributes.
1. adds a urlPart field to context
2. implements tURL to figure out the URL part
3. modifies joinContext to allow common context mismatches
   around branches to be ignored when not material as in
   <a href="/foo{{if .HasQuery}}?q={{.Query}}{{/if}}">
4. adds a pipeline function that filters dynamically inserted
   protocols to prevent code injection via URLs.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4957041
2011-08-30 11:42:30 +10:00
Nigel Tao
1f0d277cc1 exp/template/html: add some tests for ">" attributes.
R=mikesamuel
CC=golang-dev
https://golang.org/cl/4956042
2011-08-25 13:48:21 +10:00
Mike Samuel
42a56d3e81 exp/template/html: Reworked escapeText to recognize attr boundaries.
The following testcases now pass:

`<a href=x` tests that we do not error on partial unquoted attrs.
`<a href=x ` tests that spaces do end unquoted attrs on spaces.
`<a href=''` tests that we recognize the end of single quoted attrs.
`<a href=""` tests that we recognize the end of double quoted attrs.

R=golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/4932051
2011-08-25 11:24:43 +10:00