Exemplo n.º 1
0
    /*
     * Process a <script runat=server> tag
     */
    private void ProcessScriptTag(Match match, string text, IDictionary attribs, bool fSelfClosed) {
        ProcessLiteral();

        // Always ignore the spaces after a script tag
        flags[ignoreNextSpaceString] = true;

        // Check if there is a 'src' attribute
        VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(attribs, "src");
        if (virtualPath != null) {

            // Make sure it's legal to have code in this page
            EnsureCodeAllowed();

            // Get a full path to the script file
            virtualPath = ResolveVirtualPath(virtualPath);

            // Make sure access to the file is allowed (VSWhidbey 195545)
            HttpRuntime.CheckVirtualFilePermission(virtualPath.VirtualPathString);

            AddSourceDependency(virtualPath);

            ProcessLanguageAttribute((string)attribs["language"]);
            _currentScript = new ScriptBlockData(1, 1, virtualPath.VirtualPathString);

            _currentScript.Script = Util.StringFromVirtualPath(virtualPath);

            // Add this script to the script builder
            _scriptList.Add(_currentScript);
            _currentScript = null;

            // If the script tag is not self closed (even though it has a
            // src attribute), continue processing it, but eventually
            // ignore the content (ASURT 8883)
            if (!fSelfClosed) {
                flags[inScriptTag] = true;
                _scriptStartLineNumber = _lineNumber;
                flags[ignoreScriptTag] = true;
            }

            return;
        }

        ProcessLanguageAttribute((string)attribs["language"]);


        // Look for the last newline before the script block code string
        int startOfCode = match.Index + match.Length;
        int newlineIndex = text.LastIndexOfAny(s_newlineChars, startOfCode-1);

        // Use it to calculate the column where the code starts,
        // which improves the debugging experience (VSWhidbey 87172)
        int column = startOfCode-newlineIndex;
        Debug.Assert(column > 0);

        _currentScript = new ScriptBlockData(_lineNumber, column, CurrentVirtualPathString);

        // No 'src' attribute.  Make sure tag is not self closed.
        if (fSelfClosed) {
            ProcessError(SR.GetString(SR.Script_tag_without_src_must_have_content));
        }

        flags[inScriptTag] = true;
        _scriptStartLineNumber = _lineNumber;
    }
Exemplo n.º 2
0
    /*
     * Process a server side SCRIPT tag
     */
    private void ProcessServerScript() {
        // Get the contents of the script tag
        string script = GetLiteral();

        // Nothing to do if it's empty.
        // Unless we're in GenerateCodeCompileUnit mode, in which case
        // we want the empty block (VSWhidbey 112777)
        if (String.IsNullOrEmpty(script)) {
            if (!IgnoreParseErrors)
                return;

            script = String.Empty;
        }

        // Add this script to the script builder, unless we're
        // supposed to ignore it
        if (!flags[ignoreScriptTag]) {

            // First, give the PageParserFilter a chance to handle the code block
            if (!PageParserFilterProcessedCodeBlock(CodeConstructType.ScriptTag, script, _currentScript.Line)) {
                // Make sure it's legal to have code in this page
                EnsureCodeAllowed();

                _currentScript.Script = script;
                _scriptList.Add(_currentScript);
                _currentScript = null;
            }
        }
        // Reset the StringBuilder for the next literal
        _literalBuilder = null;
    }